Reputation: 6318
ok so im bringing in a test external swf like so:
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("load2.swf");
loader.load(url);
addChild(loader);
Now im trying to envoke a goto and play like so:
var loaded:Object;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoaded);
function handleLoaded(e:Event):void {
loaded = e.target.content;
}
load1.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(e:MouseEvent):void {
if (loaded) {
loaded.gotoAndPlay("outro");
}
//other content here.
}
this simple external test swf has 10 frames. @ frame 1 theres a "intro" label, @ frame 5 theres a "stop" action, and on frame 6, theres an "outro" label.
problem is that, when i click the button, it reloads the external swf and plays from frame 1.
any ideas/tips/hints etc id gladly appreciate. thanks in advance.
Upvotes: 2
Views: 2309
Reputation: 161
i improve it
function handleClick(e:MouseEvent):void
{
if (handleLoaded)
{
loaded.gotoAndPlay("outro");
}
//load new swf
}
replace to :
function handleClick(e:MouseEvent):void
{
if (handleLoaded(e))
{
loaded.gotoAndPlay("outro");
}
//load new swf
}
It works sure.. I am testing on Flex SDK 3.6a .. But i haven't test on Flash CS3/CS4/CS5 yet. Thanks
Upvotes: 0
Reputation: 15580
Try casting loaded
as a MovieClip:
MovieClip(loaded).gotoAndPlay("outro");
Ok, so that didn't fix it...
Without seeing more of the application it's hard to say more, because the code provided works fine on it's own. If this code is on a timeline, it might be worth putting a trace in alongside the load operation to see if the parent playhead is replaying.
A ha
I believe I've solved it. The issue is coming from the presence of the TLF text in load2.swf. I proved this by creating my own version of load2 without any TLF text, and this worked fine with your eerase.fla. When I added a TLF textfield to my load2, it started to show the behaviour you're experiencing. So the fix is simply to not use TLF textfields in any loaded SWF. I have tested using classic textfields with no issue.
The reason this occurs is because TLF textfields require to load data, and so it creates an artificial preloader that loads in your content. When you issue a gotoAndPlay action, you are in fact talking to this preloader, not the timeline you created, and the consequence is that the preloader 'loads' another copy of your content. This is not an actual HTTP request as the content is all inside load2.swf, hence nothing appearing in Firebug's Net panel. You can see more clearly what is being created by decompiling one of your SWF's.
Upvotes: 1
Reputation: 180
I believe you're just checking the wrong function in your if statement inside the handleClick function. You should be testing for if(handleLoaded) rather than if(loaded)...
//these 4 lines load ext swf
var loader:Loader = new Loader();// create a new instance of the Loader class
var url:URLRequest = new URLRequest("load2.swf");// in this case both SWFs are in the same folder
loader.load(url);
// load the SWF file;
addChild(loader);
//////////
//test below
var loaded:MovieClip;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoaded);
function handleLoaded(e:Event):void
{
loaded = e.target.content;
}
load1.addEventListener(MouseEvent.CLICK, handleClick);
function handleClick(e:MouseEvent):void
{
if (handleLoaded)
{
loaded.gotoAndPlay("outro");
}
//load new swf
}
Upvotes: 0
Reputation: 6127
Try listening for Event.INIT instead of Event.COMPLETE.
Quoting the documentation for LoaderInfo:
complete: Dispatched when data has loaded successfully.
init: Dispatched when the properties and methods of a loaded SWF file are accessible and ready for use.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/LoaderInfo.html
Edit: I see now that you don't call gotoAndPlay directly on load, but later. I'll leave the answer here anyway.
Upvotes: 1