views:

19

answers:

1

Hey Guys,

Having some issues accessing my param tags from within actionscript. Essentially I have the following tag:

<param name="config" value="config" />

But I am unable to access it. There are two issues that I have, and I've been searching the internet high and low for the answers.

1) How do I even access the parameter? I have some people saying use _root.config, LoaderInfo(this.root.loaderInfo).parameters["config"], and just config. None work, and searching for this stuff is so hard because it's so generic.

2) I assume that once I do find out how to access the param that is being passed, I'm going to have issues with accessing it from another file because I read somewhere during my searching that other files do not have access to global variables. If this is the case, how do I do that? I have seen _globals thrown around a couple of times and some people say it works, some don't.

Sorry if these are very basic questions, but I'm a php/.NET coder that had to update an actionscript file, and it's nothing like what I expected.

Thanks.

A: 

It seems there is a confusion between Flashvars & Flash parameters. You can access Flashvars within your code by using loaderInfo.parameters, but you won't be able to access the Flash parameters( why would you want to? )

Have a look at the following example to see the difference between the two
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000272.html

Flash parameters will set a bunch of properties to embed your movie in an HTML page, whilst Flashvars are values that you wish to use within your application.

After loading your flashvars, there are several ways to access them across your application, a simple solution ( probably not the best ) would be to create an Asset class with public static variables.

public class Asset
{
     public static var config:String;
     public static var amount:int;
}

public class Main extends Sprite
{
    public function Main
    {
        var params:Object = this.loaderInfo.parameters;

        //set your Asset variables
        Asset.config = params.config;
        Asset.amount = params.amount;

        //now that the values are set , you can use them 
        //across your app. See below...

    }
}

public class Whatever
{
       public function Whatever()
       {
           var amount:int = Asset.amount;
       }
}
PatrickS
I did read that, but I was hoping that there was a way to access them now with as3. The client that I am working with wanted to make it cleaner, but if this is the case, I guess he has no other choice.
JohnathanKong
The only thing that's not clean here is the use of global variables, there are other possibilities but that would depend on your implementation.
PatrickS
Thanks Patrick. I decided to go with your implementation. I guess I just didn't like the fact that I had to put a get string into a value. An extreme example would be if I had 10 variables that held lots of data, it would look really nasty.
JohnathanKong
If there is a lot of data, you would normally let the Flash load it as XML or JSON. The flashvars is mainly for a few values, like get parameters on a URL. If you don't want the Flash to make a separate http request for the data, there is the possibility to exchange data between Flash and JavaScript in the page, through ExternalInteface. You don't need to cram all data into flashvars.
Lars