Learn Actionscript - AHFX

Intermediate Actionscript - Passing Variables 

ahfx actionscript learning actionscript

AHFX Actionscript Home
Basic Actionscript
Intermediate Actionscript
Advanced Actionscript
About AHFX
Contact AHFX
Great Actionscript Links
 
 
 
 

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.

SUPPORT THIS SITE
If this tutorial helped you, show your support and send me something from my wish list.
Click on an item below and then choose
Adam Hayes (Gift Registry Address) for the Ship to Address.
It is that easy!
 

 

Featured Tutorials

Flash Shopping Cart Tutorial
Create a custom Flash Shopping Cart that will add, update, and show products.

Flash MX 2004 Custom Actions
Take your custom classes to the next level and have Flash treat them as built in classes.

Pass Variables to Flash
Quick and dirty way of passing variables to your flash animations.

Affordable Web Design and Hosting
Find out how you can cut your overhead by hosting with AHFX.net

Affordable Custom Art
Get your pictures custom framed. Amazing Prices. Outstanding Quality.

Premium Financing
Premium Financing with Premium Financial Advisors


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