Parameter passing in AS3 / Flex 3

If you need to do any sort of parameter passing to your AS3 or Flex Swf’s you may be wondering how to do it. In the olden days when you had a _root context on your MovieClips, and thank you very much there were your variables ready and waiting when you loaded your SWF.

Flex / AS3 has a more semantic and structured approach to the problem, well, it puts the values somewhere more semantic and structured at least.

If your application entry point is a subclass of Application you can grab your parameters from MyAppSubclass.application.parameters or in mxml Application.application.parameters.

For example I have a product ID I want to pass to a small swf when I load it.

<mx:Application 
	xmlns:mx="http://www.adobe.com/2006/mxml" 

	creationComplete="initVars()"

	 height="65">
    <mx:Script><![CDATA[
    	
        [Bindable]
        public var productId:String;
        
        // Assign values parameters to properties.
        private function initVars():void {
            productId = Application.application.parameters.productId;
        }
        
    ]]></mx:Script>
    
    <mx:VBox fontSize="18" fontFamily="Arial">
    <mx:HBox>
        <mx:Label text="Product Id: "/>
        <mx:Label text="{productId}" fontWeight="bold"/>
    </mx:HBox>
    </mx:VBox>
</mx:Application>

All I have to do is load the swf with a query string tacked on the end of the swf’s url and supply the key, value pair for my variable.

key: productId
value: 2983127 (or any other product id I need, be careful of invalid strings!)

so the swf load url would look something like…

myflex.swf?productId=2983127

The mxml will run straight from Flex Builder 3 so try it out for yourself and try loading the swf you compile into a browser (without HTML) and put ?productId=THX1138 on the end of the url…

Hey presto.

1 commentApril 22nd, 2008

can you Digg it? can you Digg it? is it del.icio.us? is it del.icio.us?

What? Another MySQL Cheatsheet…?

Did the world really need another mysql cheatsheet? I was just idly wasting time recently, and it turned out I was building a MySql cheatsheet… I was probably asleep at the time.

But anyway, it’s here, you want it you say? Well in that case…

MySql Cheatsheet, made while asleep

Add commentApril 21st, 2008

can you Digg it? can you Digg it? is it del.icio.us? is it del.icio.us?

MacBook Pro HDD Upgrade

I just recently upgraded my MacBook Pro’s 100Gb HD to a 200Gb Segate drive. I managed to find a nice guide on Extreme Tech and also a helpful video.

One thing I did have issue with was the subsequent guide to getting Mac Os X onto the new drive. Extreme Tech’s article suggests that you install Os X into the new drive with a clean install… I don’t recommend this…

Before you fit your new drive, Invest a few $$$’s in a 2.5” SATA enclosure and use Disk Utility to prepare the drive for OS X. Disk Utility has a Partitioning option which lets you setup the disk and then Erase to format it as Mac OS X ready.

Then, use the Disk Utility Restore tool … drag the current drive to the Source entry and the New drive to the Destination entry…

Using \&quot;Restore\&quot; to copy your HDD

When the copy is complete, replace the current drive with your new HDD (go with the 7200rpm 200Gb Momentus by Segate, if you vaguely trust me.) and it will boot right up and your system will be in the same state as you left it. You’re free to use the old drive however you see fit, perhaps you should put it to use as an external drive in your new SATA enclosure?

For full details of the hardware upgrade I recommend you read the ExtremeTech article

Add commentApril 1st, 2008

can you Digg it? can you Digg it? is it del.icio.us? is it del.icio.us?

AS2Dac

Almost 2 years since it was first written, AS2 NaturalDocs AutoDocumentor, now tersely titled AS2Dac has been given a bit of an overhaul.

JavaDoc support and some dynamic command line options have been added, AS3Dac is also in the works.

In the spirit of not repeating myself, there is much going on at the project home at Google Code : http://code.google.com/p/as2dacperl/ (check the Wiki for the full info…)

There is no timeline as yet for the AS3 version release.

Add commentMarch 12th, 2008

can you Digg it? can you Digg it? is it del.icio.us? is it del.icio.us?

FDT 3 Out of memory error

When you first get started with FDT3 from PowerFlasher http://fdt.powerflasher.com / http://fdt.powerflasher.de you will probably get the message…

Not enough memory to run FDT - add the following line to your eclipse.ini

-Xmx512m

On a windows machine the eclipse.ini is easy to find, and should be in the same folder as eclipse.exe, editing the file in notepad and altering the line

-Xmx256m

to the value above, should be straightforward. If you struggle with opening and saving files in notepad, sadly this blog post isn’t going to give you the file editing 101 that you sorely need.

If you are cool with the file change, restarting Eclipse and opening the FDT perspective will solve the issue.

On a Mac OS X machine things are a tiny bit trickier, the eclipse.ini file is tucked away inside the Eclipse application package, which you probably have stored in your Applications folder.

The quickest way to get at the eclipse.ini file is to Ctrl + Click the Eclipse application and select the *Show Package Contents* option from the menu.

If you then navigate to Contents/MacOS/ inside the package you’ll see eclipse.ini edit it with TextEdit or whatever you like to use to edit text files (TextMate http://macromates.com/, Eclipse, BBEdit?) and change the line

-Xmx256m

to read

-Xmx512m

Save eclipse.ini and close the finder window, restart Eclipse and you should be good to go.

This information is probably in the FDT forum, but I just figured this out five minutes ago and decided to post here instead.

Add commentMarch 3rd, 2008

can you Digg it? can you Digg it? is it del.icio.us? is it del.icio.us?

Previous Posts