Learn Mootools - AHFX

Intermediate Actionscript - Passing Variables 

ahfx Mootools learning Mootools

AHFX Mootools Home
Basic Mootools
Contact AHFX
 
 
 
 

Actionscript 2.0 Variable Passing (Easy)

This is an easy tutorial, but it can be very useful for those that need to pass variables into flash. I use this for many different purposes. It can be everything from passing the name of a table in a database to just passing the name of a video file to your custom made flash video player. All you do is pass the variable just like you would in a url. For example, my.swf?video=sweetvideo. You just append the variable name, video, with the value you want to pass, sweetvideo. These variable/value pairs are read into flash by the following code:

var passed:String = video == undefined ? "Nothing Passed" : video;
inner_txt.text = passed;

 

This code will display the value you pass into the movie assuming that you have created a dynamic text field named inner_txt. If you fail to pass a variable, it will display Nothing Passed.

For all of those non "Computer Science" people out there. The var passed:String = video == undefined ? "Nothing Passed" : video; is the shorthand version of doing the following:

if (video == undefined){
   var passed:String = "Nothing Passed";
}
else {
   var passed:String = video;
}

 

Here is a sample of html code to make this work:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs
/flash/swflash.cab#version=7,0,0,0"
width="550" height="400" id="passing" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="passing.swf?video=sweetvideo" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="passing.swf?video=sweetvideo" quality="high" bgcolor="#ffffff" width="550" height="400" name="passing" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
 

This can be very useful for creating one flash video and using it in many different locations. All you need to do is check the variable that is passed. However you should be careful not to give away too much with this variable, because someone could hack your swf and pass bogus information to it.

Back to Intermediate Actionscript page.

If this FREE tutorial helped you at all, please consider clicking on a link to help support this site.
---OR---
Donate to the cause by sending us an Amazon Gift Certificate.
Click Here to Send an Amazon Gift Certificate to info@ahfx.com

 


 

Creative suite generic 125x125

Featured Tutorials


 
AH Digital FX Studios
Disclaimer | Site Map | Idaho Web Design