开发者

functions and variables

We开发者_如何学Cll the question is quite simple but I somehow can't figure it out.

For example I have string variable ts. After my loader loads image in movieclip instance i want to change ts value to something. The problem is - ts value isn't changing on my doneLoad function. Here's the code

var ts:String = "loading";   

var imgload = new Loader();

imgload.load(new URLRequest("http://images.op.com/cards/up1x3941204.jpg"));

imgload.contentLoaderInfo.addEventListener(Event.COMPLETE,doneLoad);

function doneLoad(e:Event):void {
 ts = "done";
}

trace(ts); // returns "loading"

What's the problem?


Your problem is that trace(ds) is called before the function doneLoad ever runs.

doneLoad is a callback function and doesn't run until ofater the Loader completes. Your call to trace(ds) is outside the callback and therefor runs as soon as the app starts (or whenever the rest of the code runs). Hence, when trace is called...the value is still "loading".

Change your code to:

var ts:String = "loading";
var imgUpload:Loader = new Loader();

imgload.load(new URLRequest("http://images.op.com/cards/up1x3941204.jpg"));
imgload.contentLoaderInfo.addEventListener(Event.COMPLETE,doneLoad);

function doneLoad(e:Event):void
{ 
    ts = "done";
    trace(ds);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜