Forums: Flash:

 

AS3 - add On

first
 

scudsucker AS3 - add On

Edit.. Title should read "AS3 - add OnEnterFrame event to get currentFrame



I have been given a small job, to load a sequence of animated .swfs in a loop.

I need to compare the current loaded clip's currentFrame to its totalFrames in order to know when it has completed playing, and to load in the next.


// ... snip ...//
public class Main extends MovieClip
{
private var _xmlFile:String = "movieList.xml";
private var _containerMovie:MovieClip;
private var _baseUrl:String;
private var _flashFolder:String;
private var _movieXMLListData:XMLList;
private var _currentMovie:Number = 0;


// ... snip ...//



private function loadMovie(_currentMovie:Number):void
{
var movieClip:String = _movieXMLListData[_currentMovie].@file;
var clickThrough:String = _movieXMLListData[_currentMovie].@clickThrough;


var loader:Loader = new Loader();
var placeHolder:MovieClip = new MovieClip();
placeHolder.name = "placeHolder";
placeHolder.addChild(loader);
_containerMovie.addChild(placeHolder);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCompleteEvent);

loader.load(new URLRequest(_baseUrl + _flashFolder + movieClip));

}

private function onLoadCompleteEvent(loadEvent:Event):void
{
trace("load succeeded");
_containerMovie.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

private function onEnterFrame (event:Event):void
{
trace("tick");
trace("frame " + _containerMovie.placeHolder.currentFrame); // error on this line
}

// ... snip ...//

}



I get an error message (in FlashDevelop) - line 107 is the last line of code above, in bold.

[Fault] exception, information=TypeError: Error #1010: A term is undefined and has no properties.
Fault, onEnterFrame() at Main.as:107

This is some sort of scoping issue, surely, as I can trace _containerMovie.currentFrame (which is always 0).

How then do I address these properties of a swf loaded into a Loader?

Also, in AS1 & 2, when loading a swf into a movieclip, the movieclip's onEnterFrame, etc etc were deleted - which is why I created the placeHolder clip to hold the loader. Is this still the case?


__________________________
Hmbeh.
quote
 

DontBogartMe

the loaded SWF's timeline is actually in loader.content, not just loader. So the full path to it would be:

_containerMovie.placeHolder.loader.content - but that's not right either because loader.content isn't a MovieClip type, so it has no timeline to check.

You need to change a few things:
1. Don't add the loader to placeholder in the loadMovie method.
2. Instead, in the onLoadCompleteEvent method do this:

		private function onLoadCompleteEvent(loadEvent:Event):void 
{
trace("load succeeded");
// Use the loadEvent parameter to access the loaded clip.
_containerMovie.placeHolder.addChild( MovieClip(loadEvent.target.content) );
_containerMovie.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}


Now your placeholder contains 1 child clip, which should be the SWF you loaded, but it's unnamed so you get at it with getChildAt(0)


		private function onEnterFrame (event:Event):void 
{
trace("tick");
trace("frame " + MovieClip(_containerMovie.placeHolder.getChildAt(0)).currentFrame);
// Note I had to cast to MovieClip there because getChildAt returns an object of type DisplayObject, and that doesn't have a timeline.
}


I haven't tested any of this... give it a go and post any errors.

 

scudsucker

Hey, thanks.

Sorry to say-


Type Coercion failed: cannot convert flash.display::AVM1Movie@12545e1 to flash.display.MovieClip

thats on

_containerMovie.placeHolder.addChild( MovieClip(loadEvent.target.content) );


Thats a bit irritating, the Adobe docs seem to say that casting a DisplayObject to Movieclip is possible - yet it is not casting and using the alternate,

loadEvent.target.content as MovieClip;

returns null

livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000216.html

Copy/paste code from the comments in the Adobe help also fails (in CS3 IDE.) with the same coersion error


__________________________
Hmbeh.
quote
 

scudsucker

An AVM1Movie instance is not the same as a MovieClip instance. It is a display object, but unlike a movie clip, it does not include timeline-related methods or properties. The parent AVM2 SWF file will not have access to the properties, methods, or objects of the loaded AVM1Movie object.


Bugger. Well that pretty much prevents me from continuing, as I do not have control over the loaded .swfs and they are published for AS1 or 2, even though they do not contain code.

So i guess I'll have to stop research on this, even though I'd like to finish it. Grr.


__________________________
Hmbeh.
quote
 

DontBogartMe

maybe you could write a little loader SWF in AS2 that loads and plays the clip you want, and also sets up comms with AS3 and the AVM2?

So the new loader SWF can talk to the AVM1 movies, and via LocalConnection it can communicate with the main AVM2 movie.

I think that should work.

 
first
 

Forums: Flash: AS3 - add On

 
New Post
 
You must be logged in to post