views:

49

answers:

1

alt text

I need more examples animating external files. My ball in the external swf is suppose tick across the stage. How do I get "ldr.swf" to load "ball.swf" and tell it to move the ball across the stage?

alt text

var bgLoader:Loader = new Loader();
bg_mc.addChild(bgLoader);
var bgURL:URLRequest = new URLRequest("ball.swf");
bgLoader.load(bgURL);


import flash.utils.*;
var myTimer:Timer = new Timer(200);
myTimer.addEventListener(TimerEvent.TIMER, timedFunction);
myTimer.start();

function timedFunction(eventArgs:TimerEvent)
{   
var bl:MovieClip = event.target.content.root.ball;
//
bl.x += 10;
    addChild(bl); 
}
+2  A: 

The only things I see wrong are:

  1. Waiting for ball.swf to load.
  2. Mistaking the TimerEvent target for the loader handler

e.g.

var bl:MovieClip;
var bgLoader:Loader = new Loader();
var bgURL:URLRequest = new URLRequest("ball.swf");
bgLoader.load(bgURL);
bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, bgLoaded);

var myTimer:Timer = new Timer(200);
myTimer.addEventListener(TimerEvent.TIMER, timedFunction);


function bgLoaded(event:Event):void{
bl = event.target.content.root.ball;//hopefully this path is correct
myTimer.start();
addChild(bl); 
}
function timedFunction(eventArgs:TimerEvent)
{ 
bl.x += 10;
}

HTH, George

George Profenza
Thanks mate, that really helps.
VideoDnd