Forums: Flash:

 

Another dumb question:testing URL parameters

first
 

Stickman Another dumb question:testing URL parameters

I really am rusty with this stuff...

I'm creating a Flash movie that will depend on a parameter passed in from the page it's embedded in. While I'm in development, is there s simple way to simulate this behaviour when testing within Flash itself? BTW, I'm stuck with Flash 8 on this project.

Cheers!

StickBlog - random developer stuff
quote
 

DontBogartMe

right at the start of the movie, set that param to whatever value you want to use to test.

e.g. if the param is called user_id, then do:
_root.user_id = whatever;

or you might be able to just do

user_id = whatever;

 

jimmyn

One method I've been using a lot of lately is using short-circuit booleans or trinary operators to set a variable to a given parameter or a default if the parameter doesn't exist. For example:


var myDynamicString:String = _root.queryStringParam || "defaultValue";

// or

var myDynamicString:String = (_root.queryStringParam !== undefined) ? _root.queryStringParam : "defaultValue";

The first syntax using the || uses actionscripts loose typing nature to get a quick settings in place. If _root.queryStringParam is set to anything (and also not 0 or false) it will be stored as the value, otherwise the default value is stored.

The second syntax is a little more verbose, but technically a little cleaner. If the queryStringParam is defined and set to anything (meaning something came through from the dynamic context) that value will be used, otherwise the default value will be used.

From this point you then just use your own variable (in this case myDynamicString) when you want to use the value of the property. I generally avoid keeping the name of the variable I want to use the same as the name of the variable getting passed to me to avoid any confusion--as long as I use my variable I know what I am using. Because default settings have been used, your code can be assured to always have some value and that will make testing much easier.

 

Stickman

Thanks guys. Don't know why, but I was sure there was a way to set Flash itself up so that you could set parameters externally when testing. shrug.gif

StickBlog - random developer stuff
quote
 
first
 

Forums: Flash: Another dumb question:testing URL parameters

 
New Post
 
You must be logged in to post