A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] How exactly do you replace _level in AS3?

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    10

    resolved [RESOLVED] How exactly do you replace _level in AS3?

    I've seen the whole migration warning:

    Migration issue: _level is no longer supported. For more information, see the flash.display package

    I've looked at the package, but it's like searching through a foreign language book to find one word. I was always used to this:

    Code:
    var myChannel:String = _level0.channel;
    How do I replicate this behavior? I want to embed the swf file so that it is calling "example.swf?channel=1&episode=12" and I want to be able to access the variables from there.

    Any helps is appreciated.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Forget about _level for this. What you need is to set and get flashvars.

    Are you certain that you want to embed the variables in the URL? The proper way to do it is to set the flashvars parameter of the embed and/or object tags that put the swf on the page.

    Assuming you do set flashvars, you can access them from the document class like this:
    Code:
    var params:Object = loaderInfo.parameters;
    trace(params.channel); //1
    trace(params.episode); //12
    If you do need to extract the info from the url, it's different, and less supported.
    Code:
    var myURL:String = loaderInfo.url;
    var questionIndex:int = myURL.indexOf("?");
    if(questionIndex != -1){ //there is a ? in the URL
      var varsPart:String = myURL.substring(questionIndex+1);
      var vars:URLVariables = new URLVariables(varsPart);
      for (var name:String in vars) {
        trace(name + " = " + vars[name]);
      }
    }

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    10
    I have to be missing something simple here.

    First, I changed the html code for the embed and added:

    Code:
    	<param name="channel" value="0" /> 
    	<param name="episode" value="1" />
    Also added it to the <embed> tag. Then, in the flash file, I added:

    Code:
    	var params:Object = loaderInfo.parameters;
    	var myChannel:int = params.channel; //0
    	var myEpisode:int = params.episode; //1
    Just after this, I have a call to get an XML file to load. Because of the multiple changes from as2 to as3, I decided to create a different XML file for each playlist for my player, named X-X.xml, with the first X representing the channel and the second X representing the episode. When I call the xml, however,

    Code:
    loader.load(new URLRequest("http://www.domain.com/vidfolder/"+myChannel+"-"+myEpisode+".xml"));
    ...it ends up always calling http://www.domain.com/vidfolder/0-0.xml, no matter what I set the params to.

    I am sooooooooo lost on this one. Thanks for all the help.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yes, you're missing something simple: That's not how to set flashvars.

    Instead of a parameter for each, you need a single parameter named flashvars.
    Code:
    <param name="FlashVars" value="channel=0&episode=1" />
    http://kb2.adobe.com/cps/164/tn_16417.html

  5. #5
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    key-value pairs appended to the swf filename act just like flashvars

    movie.swf?channel=0&episode=1

    have channel and episode passed to the loaderInfo.parameters property, just as if they had been passed using flashvars

  6. #6
    Junior Member
    Join Date
    Jan 2010
    Posts
    10
    Thanks, guys, for helping a very forgetful n00b. I had to use this before, and completely forgot about it.

    Mods, would it be possible to add a smilie? I'm thinking of something that would be used a lot, like :foreheadslap:

    Thanks again. Problem resolved. Flash working.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center