anon255058
anon255058

Reputation:

animate external swf

alt text http://www.ashcraftband.com/myspace/videodnd/board1.jpg

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 http://www.ashcraftband.com/myspace/videodnd/exampletick.jpg

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); 
}

Upvotes: 0

Views: 162

Answers (1)

George Profenza
George Profenza

Reputation: 51837

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

Upvotes: 1

Related Questions