asHelpDesk exists to provide a place for anyone who is frustrated by ActionScript to find tips. Realize you are not alone! Everyone who uses ActionScript sometimes wants to shove their keyboard through their computer screen. But alas, we're here to help!

Feel free to post questions or comments and as a community we will do our best to answer them.

Learning Adobe Flex 3 Series - Part 1


Flex: Comparing Flash, Flex, Flash Player, and AIR

Accessing HTML Querystrings in AS3

You can pass variables to SWF files in the object/embed code used to display a SWF in HTML. You can do this two ways, one using URL variables (query string) at the end of the SWF path, or through the FlashVars property.

HTML Code:
<!-- URL Variables -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="640" height="500" align="middle">
	<param name="allowScriptAccess" value="sameDomain" />
	<param name="movie" value="flashMovie.swf?myVar=1" />
	<param name="quality" value="high" />
	<param name="bgcolor" value="#EFF7F6" />
	<embed src="flashMovie.swf?myVar=1" quality="high" bgcolor="#EFF7F6" width="640" height="500" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
HTML Code:
<!-- FlashVars -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" align="middle">
	<param name="allowScriptAccess" value="sameDomain" />
	<param name="movie" value="flashMovie.swf" />
	<param name="quality" value="high" />
	<param name="bgcolor" value="#FFFFFF" />
	<param name="FlashVars" value="myVar=1" />
	<embed src="flashMovie.swf" FlashVars="myVar=1" quality="high" bgcolor="#FFFFFF" width="550" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

In ActionScript 2, these variables were simply defined as variables in _root. This has changed for ActionScript 3. Now these variables are accessible in a parameters object located in the root loaderInfo object.

Given the HTML embed code above, you would access the myVar property using:

ActionScript Code:
root.loaderInfo.parameters.myVar;

How to get a list of child objects that are inside another object

Here is an easy way to get a list of child objects from inside another object.

for(x=0; x < my_mc.numChildren; x++){
trace("Type:"+my_mc.getChildAt(x)+"Name:"+my_mc.getChildAt(x).name);
}

Using the MouseWheel to Scroll in AS3

Here is a nice little chunk of code that I wrote to help you enable the MouseWheel in your Flash AS3 files.

// Import MouseEvent
import flash.events.MouseEvent;

// Create MouseWheel Event
public function handleMouseWheel(event:MouseEvent){
trace(event.delta);
}

// Add MouseWheel Listener
addEventListener(MouseEvent.MOUSE_WHEEL,handleMouseWheel);

This will trace the movement from the MouseWheel and that value can be used in your Flash movie however you would like. Enjoy!

UPDATE: It has come to my attention that Firefox doesn’t always like this.  Here is how you work around it. (Thanks Ben)

In JS…

function mozScroll(e)
{
if(cork.PercentLoaded() == 100)
if(cork.FirefoxMouseWheel)
cork.FirefoxMouseWheel(0, e.detail);
}
if(window.addEventListener)
{
window.addEventListener('DOMMouseScroll', mozScroll, false);
}

…and in AS3…

ExternalInterface.addCallback("FirefoxMouseWheel", ZoomInOut);
...
public function ZoomInOut(event:* = null, mozDeltaOverride:* = null):void {...}