Remember that events happen in the future - so you want to set up all your listeners on an object before you ask it to do something - in the code below, you call "loader.load" before adding the listeners - that may not work if the thing loaded is small / cached.

Also, you might want to be careful using the COMPLETE event for loaded content - you should look at using the INIT event instead - COMPLETE means it's finished loading, not that it is "ready" for interacting with. Use INIT to be sure you can read properties and call methods on your loaded content.

With RemoveMiddle - like Jason said, what are you listening for - the end of the 2nd Tween timeline? If so, your code may be wrong, you probably want to set up timeline2 inside the RemoveMiddle function??

Glen

John Singleton wrote:
Hi;
I struggle with event listeners and knowing to what objects to attach them. I 
have the following code:

        function SpinMiddle()
        {
            big_container.addChild(container_middle2)
            var path:String = "images/mid" + j + ".png";
            var req:URLRequest = new URLRequest(path);
            var loader:Loader = new Loader();
            loader.load(req);
loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void{ trace(e) }); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, SpinMiddleLoaded);
        }
function SpinMiddleLoaded(evt:Event):void
        {
            var loaderInfo:LoaderInfo = evt.target as LoaderInfo;
            var displayObject:DisplayObject = loaderInfo.content;
            displayObject.width = 319;
            displayObject.height = 502;
            container_middle2.addChild(displayObject);
            container_middle2.x = 349;
            container_middle2.y = -482;
            mid_done = true;
            var rand:Number = new Number(randomNumber(300, 500));
            var timeline:TimelineLite = new TimelineLite({onComplete: 
RemoveMiddle()});
            timeline.append(new TweenLite(container_middle, rand/100, {alpha: 
1}));
            timeline.append(new TweenLite(container_middle, 1, {x:349, y:522}));
            var timeline2:TimelineLite = new TimelineLite();
            timeline2.append(new TweenLite(container_middle2, rand/100, {alpha: 
1}));
            timeline2.append(new TweenLite(container_middle2, 1, {x:349, 
y:20}));
        }
function RemoveMiddle()
        {
            container_middle2.addEventListener(Event.COMPLETE, AllDone);
        }
AllDone() is never called, even though a trace in RemoveMiddle() traces. I've tried replacing container_middle2 with big_container in RemoveMiddle() but with no luck. Please advise.
TIA,
John



_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to