AS3 gotoAndStop() on the timeline of a loaded SWF
I'm working on a new ad unit called a Filmstrip for NineMSN (demo here) which basically loads in 5 SWFs vertically. Only one of these 5 is visible at a time (with the exception of a a portion of two SWFs between UP and DOWN transitions.
What I'm trying to achieve is ensure that when the user clicks on UP or DOWN, the SWF you scroll to will be playing from the beginning.
How can I target the main timeline of an SWF loaded as per below and call gotoAndStop()
on this?
var loader:Loader = new Loader();
loader.y = index * 600;
loader.load(
new URLRequest(_assets["ebMovie" + (index+1)])
);
addChild开发者_开发技巧(loader);
If the above is not possible, what's the most viable solution to achieve similar? Maybe like quickly unloading/reloading the SWF (I'm just concerned about the issues this could potentially open me up to such as the connection dropping out between clicking UP or DOWN and the ad breaking).
One of the major curveballs I had here was that content
is inaccessible until it's actually been loaded (duh), so firstly we need to attach an event listener to loader.contentLoaderInfo
before we can do anything:
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _loaderComplete);
Now we can work with content
in the triggered function:
private function _loaderComplete(e:Event):void
{
// Capture instance of LoaderInfo
var info:LoaderInfo = e.target as LoaderInfo;
// Remove triggering listener
info.removeEventListener(Event.COMPLETE, _loaderComplete);
// Typecast content to MovieClip
var timeline:MovieClip = MovieClip(info.loader.content);
_timelines.push(timeline);
}
The above will typecast the content property to a MovieClip
representing the Main Timeline of the loaded SWF, allowing full control over it.
I would use a manager class to keep track of the swfs and the selected index. Then you need to reference the loader content to access the timeline.
var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.gotoAndPlay(2);
精彩评论