I tried googling but nothing came up (atleast not that i found it) so i tried doing it myself.
In my app im embedding a swf file and then use this code to display it:
_animation_swf = new LaserAnimation() as MovieClipLoaderAsset;
_animation_loader = new SWFLoader();
_animation_loader.load(_animation_swf);
this.addChild(_animation_loader);
I googled and found out MovieClipLoaderAsset has methods to determine current frame playing and total frames. Perfect for me. I wrote this little class:
package components.init_screen.components
{
import events.AnimationPlayEvent;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.core.MovieClipLoaderAsset;
public class Animation extends MovieClipLoaderAsset
{
private var _timer:Timer;
public function Animation()
{
super();
_timer = new Timer(100);
_timer.addEventListener(TimerEvent.TIMER, detectPlayback);
this.addEventListener(Event.COMPLETE, startDetection);
}
/**
* starts when asset finishes loading
* */
private function startDetection(event:Event):void{
_timer.start();
}
/**
* is being repeated periodically and detects if animation has finished playing
* */
private function detectPlayback():void{
if(currentFrame >= totalFrames){
_timer.stop();
dispatchEvent(new AnimationPlayEvent(AnimationPlayEvent.PLAY_COMPLETE));
}
}
}
}
and changed the display code to this:
_animation_swf = new LaserAnimation() as Animation;
_animation_swf.addEventListener(AnimationPlayEvent.PLAY_COMPLETE, addLanguageMenu);
_animation_loader = new SWFLoader();
_animation_loader.load(_animation_swf);
this.addChild(_animation_loader);
The problem is it reports a runtime error: Cannot access a property or method of a null object reference. on line where i add an event listener. If I try commenting that line it seems the app just freezes… no http service response, no animation showing…
Does anyone know what i did wrong?