Skip to main content
Mr. Baker the Shoe Maker
Inspiring
November 24, 2012
Answered

Loader Class: How can I go to specific scenes and frames?

  • November 24, 2012
  • 2 replies
  • 1144 views

Is there a way using the loader class to go to a specifc scene and frame in the file that I am loading? For example, I would like to go to frame 3 in scene 2 in the file I'm loading "File.swf"

Here is the code that I am using to load the file. Now I would like to go to a specific frame and scene within in the file:

var LoaderHome:Loader = new Loader();

LoaderHome.load(new URLRequest("File.swf"));

addChild(LoaderHome);

Questions #2

Also, when I add the file "File.swf" should I remove the existing movie for performance/memory management? If so, how would I remove a child where the code is another movie?

This topic has been closed for replies.
Correct answer Ned Murphy

Before you can try to manipulate the file, you need to know that it has finished loading.  To do that you need to add an event listener to the contentLoaderInfo object/property of the Loader.  You can then use the event handler function for that listener to trigger the action for the loaded file.

2 replies

Ned Murphy
Legend
November 24, 2012

Here's some sample code to go with what I just explained.

var LoaderHome:Loader = new Loader();
LoaderHome.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
LoaderHome.load(new URLRequest("File.swf"));

addChild(LoaderHome);

function swfLoaded(evt:Event):void {
     MovieClip(evt.target.content).gotoAndStop(3,"scene2");
}

Mr. Baker the Shoe Maker
Inspiring
November 25, 2012

Ned,

Thanks!

I have a few of questions though.

1) In the line "MovieClip(evt.target.content).gotoAndStop("1","Watch");", what is the significance of "MovieClip"

2) Since I am developing for mobile, should I remove the .swf that is no longer showing? If so, how do I do this? In other words, when I add a .swf file is the other .swf file still active but not seen?

3) I am working with in which the user may go back and forth between .swf files. Do you have any suggestions as regards performance?

Ned Murphy
Legend
November 25, 2012

1) It's become somewhat of a habit for me to cast a generic object like "target" or "content" as a type that agrees with the methods that are called upon (gotoAndStop/Play are timeline/MovieClip methods)... a result of errors occuring at times when you don't.  You might be able to remove it without a problem.  Often the compiler knows exactly what class an object is but it wants to complain anyways. If you ever get an error regarding "implicit coercion", it is of this nature.

2) If the swf you are talking about is the parent of the Loader, you don't want to do that... it will remove the Loader as well.

3) I don't have a recommendation due to next to no experience working in mobile matters.  You should start another posting to see if someone can give you a proper answer. I don't know if this also relates to your second question so you might want to cover it all.

Ned Murphy
Ned MurphyCorrect answer
Legend
November 24, 2012

Before you can try to manipulate the file, you need to know that it has finished loading.  To do that you need to add an event listener to the contentLoaderInfo object/property of the Loader.  You can then use the event handler function for that listener to trigger the action for the loaded file.