Skip to main content
Participating Frequently
September 11, 2012
Question

goto Label call from Javascript inside nested swf

  • September 11, 2012
  • 1 reply
  • 2048 views

Hello All,

I need some help.

I have tried various methods to get this to work, including External Interface which probably was too complex for my momentary knowledge.

I have following test case which works fine:

A HTML button calls the following function, the Flash movie jumps then to the desired frame Label "redframe"

function golabel() {

  if (movieIsLoaded(thisMovie(movieName))) {

    thisMovie(movieName).TGotoLabel("_level0/","redframe");

  }

}

My problem is the following: I want Flash to go to a frame label inside of a swf, which is loaded into the main-swf by a preloader.

The loaded swf has the ID 'uiLoader'.

Inside of 'uiLoader' is a container called 'mainContainer'.

Inside of 'mainContainer' I want to go to the label 'string_power_measurement'.

Using "_level0.uiLoader.mainContainer" doesn't work for me.

function golabel2() {

  if (movieIsLoaded(thisMovie(movieName))) {

    thisMovie(movieName).TGotoLabel("_level0.uiLoader.mainContainer","string_power_measurement");

  }

}

Does anyone has an idea how to solve this?

Apart from that I have a function which tells Javascript if the Main-Swf is loaded to prevent errors. I don't know if this also addresses the load of the nested swf. If not I would help how to address the nested swf next to the main swf. Ideal would be a function not only stops itself if the swfs aren't fully loaded, but which waits until the movie is fully loaded and then triggers the function.

This is my Code:

function movieIsLoaded (theMovie) {

  if (typeof(theMovie) != "undefined") {

    return theMovie.PercentLoaded() == 100;

  } else {

    return false;

  }

}

Any help would be great.

Many thanks,

Felix

This topic has been closed for replies.

1 reply

sinious
Legend
September 11, 2012

You're in the ActionScript 3.0 forums but when you say "_level0" which is ActionScript 2.0 it makes me question what version of AS you're using.

Are you using AS2.0 or 3.0? "_level0" does not exist in AS3.0. Are you recently converting from AS2.0 to 3.0?

Please post the relevant ActionScript as well. You hava JavaScript there but we need to see the functions that are handling the JavaScript requests.

Participating Frequently
September 11, 2012

Hello Sinious,

thank you for your quick reply. There's no function in my Flash file. The script seems to work without any inside-Flash function. The file is AS3. I found a tutorial which gave me this code, which worked fine for me on the main-swf. I didn't know "_level0" is AS2 but for some reason it works.

I just tested the following line, using "_root" which works aswell (putting in any other value doesn't, meaning this line is not ignored):

    thisMovie(movieName).TGotoLabel("_root","redframe");

But "_root.uiLoader.mainContainer" doesn't work.

Thanks,

Felix

sinious
Legend
September 11, 2012

You learn something new every day and I can honestly say I don't see how that JS code is working at all, but flash must support this API. I'm just not aware of it.

Yes, _level0 and _root can but not always mean the same thing in AS2.0, but does not exist in AS3.0. That's why that JS makes no sense to me. Are you absolutely sure it's AS3.0 and not 2.0?

If you put code in Flash and export with a template that supports fscommand (I think they still call it that) then communication is opened in the SWF between the host (browser/JS) and ActionScript. You call functions you write from JavaScript, passing arguments if you desire, and flash receives the request and performs it.

That aside, the Loader class needs to be used a specific way. When you load a SWF into a Loader object it puts the contents into a property reference called "content". So if you loaded a MovieClip inside a Loader you would gain access to it like this in AS:

// access a MovieClip loaded in a Loader named mainContainer

var mc:MovieClip = MovieClip(mainContainer.content);

// play a label

mc.gotoAndPlay("string_power_measurement");

You can't access it like you're trying: someLoader.mainContainer; you're missing the .content property. You can try to rewrite that JS line like so but I'd be suprised (confused and horrified) if it works:

thisMovie(movieName).TGotoLabel("_level0.uiLoader.mainContainer.content","string_power_measurement");

I'd be really suprised to see that work... Do note that the forum inserts spaces in long strings of characters (like it did to your post) so remove any excess spaces on copied code.