English 中文(简体)
三、与《行动》中具有动态内容的TLF案文不合作的情况 3
原标题:Scrollbar not working with TLF text with dynamic content in ActionScript 3

I m 创建一个简单的闪电项目,有闪电5和行动3。

我想做的是,我要动态地更新带有特定来源和目的地的TLF文本集装箱,例如loadData(文本_placeX,“标记......xml”);

它像一个药店一样工作,但问题是,我无法为我的文本使用任何滚动屏障。 我在集装箱中添加了<条码> 商品编码<>。 我失踪了什么?

另一个问题是,在装上新数据之前,我怎么能空出我的正文集装箱?

我的法典是:

import fl.text.TLFTextField;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.text.TextFieldAutoSize;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;
import fl.controls.ScrollBar;

var ldr:URLLoader = new URLLoader();
var flow:TextFlow = new TextFlow();

function loadData(text_place, fileURL:String):void {
    text_place.border = true;
    ldr.dataFormat = URLLoaderDataFormat.TEXT;
    ldr.addEventListener(Event.COMPLETE, function(evt:Event){ ldr_complete(text_place) }, false, 0, true);
    ldr.load(new URLRequest(fileURL));
    ldr.addEventListener(IOErrorEvent.IO_ERROR, loadError);
}

function ldr_complete(text_place:TLFTextField):void {
    ldr.removeEventListener(Event.COMPLETE, ldr_complete);
    ldr.removeEventListener(IOErrorEvent.IO_ERROR, loadError);
    initText(text_place, ldr.data);
}

function loadError(e:IOErrorEvent):void {
    trace("Error loading an external file. The server may be busy. Try refreshing the page.");
}

function initText(text_place:TLFTextField, fileContent):void {
    flow = TextConverter.importToFlow(fileContent, TextConverter.TEXT_FIELD_HTML_FORMAT);
    flow.flowComposer.addController(new ContainerController(text_place, text_place.width, text_place.height));
    flow.flowComposer.updateAllControllers();
}

<><>UPDATE: 当我使用<代码>initText的功能内容,而我则使用<代码>text_place.tlfMarkup = 文档Content; 运行;但我关于<代码>TextFlow的选择却缺失。 在将内容放在文字领域之后,我也失踪了“最新滚动”。

最佳回答

我认为,这个问题可能是:

ldr.addEventListener(Event.COMPLETE, function(evt:Event){ ldr_complete(text_place) }, false, 0, true);

You have an anonymous function here (function(evt:Event){...) which passes the object text_place to the function ldr_complete(). However, you do not have access to text_place, since it is a variable declared within a different scope. If you make the function into a named one, you will not assume that you have that access. E.g.,

function loadCompleteHnd(evt:Event):void{
[...]
}

然而,您仍须在<代码>text_place上查阅。 因此,您可以将<代码>文本_place变成一个等级(全球)变量,并随时确定这一变量。 但是,这可能会造成一种种族条件的风险——如果你负荷缓慢的话,你可能会试图从两个地方一度改变目标。

另一种选择是建立一个全新的<代码>。 活动,扩展<代码>。 届时,您可以为<代码>Event.COMPLETE的听众创建另一个参数。 这很复杂,是学习曲线的范畴,但使事件更加多变。

在这两种情况下,你都可能要树立一个旗帜,告诉你,其他东西是否是编辑同一物体。 它不是无ool可击的,但它可以拯救一些头痛。

问题回答

暂无回答




相关问题
Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签