Welcome!

Adobe Flex Authors: Maureen O'Gara, John Ryan, Fuat Kircaali, Chris Fleck, Jason Dolinger

Related Topics: Adobe Flex

Adobe Flex: Article

5 Flash Tips: onLoad Event Handler Not Working With loadMovie?

Guy Watson shares a few quick hints

Tip #1: Neat Fix - onLoad Bug
I have heard so many people moan on the many community forums and mailing lists about the onLoad event handler not working with loadMovie and although I have already posted a fix for the problem (www.actionscripts.org/forums/showthread.php3?threadid=13830), I found this very small and functional fix that does the same thing, a while ago on the Flashcoders Mailing List: http://chattyfig.figleaf.com/mailman/htdig/ flashcoders/2002-October/049415.html and so if you see the question, forward people to http://chattyfig.figleaf.com/apache2-default/.

Tip #2: Bug - Sound.loadSound & GetRight
If you have GetRight (www.download.com/GetRight/3000-2071_4-10005533.html) installed on your computer, a download management utility, and you view a Flash movie that attempts to load an mp3 sound file into the Flash Player dynamically using the Sound.loadSound method, GetRight stops the loading of the mp3 file and asks you to choose a location to save the mp3 file on your local computer; whether you choose to download the file or not, Flash still does not load the file into the player, which raises an issue.

GetRight is one of the most, if not the most popular download utility and this is the default behaviour of the program, of course these settings can be changed, by removing the hook for mp3 files but Flash alone cannot do this automatically for you, this is a manual process that viewers of your site will have follow if they want to listen to dynamically loaded sounds on your site...

To fix the problem, I assume that by changing the file extension of your mp3 files to something which is not registered as a download hook in GetRight will do the trick, but of course, if GetRight actually checks the MIME -type of the file instead of using the files extension, then this will not solve the problem. Changing the mime-type is not only a complex process for novices, it will not solve the problem, because the Flash Player will not play the file if its MIME-type is not set to type mp3.

Tip #3: Stage.showMenu
It is all in the name, Stage.showMenu is a Boolean property of the Stage object that defines whether to display the menu or not, when the user right-clicks on your Flash movie.

A boolean value is either true or false, 0 or 1, on or off, the Stage.showMenu value can either be true or false:

true - Show the menu on right-click
false - Down show the menu on right-click

Please bear in mind, that this isn not the answer to all our prayers, when you turn the right-click menu off, the 'About Flash 6 Player' and 'Settings' options are still displayed, so no, you cant 'fully' remove the right-click menu. The actionscript:

//turn off the right-click menu
Stage.showMenu=false;

Tip #4: System.security.allowDomain
This undocumented method grants permission for the specified domain(s) to access objects and variables in the Flash movie that calls the allowDomain command. This property had to be implemented because of the changes made to the Security Sandbox in the Flash 6 Player...

I have two movies, 'a.swf' and 'b.swf', 'a.swf' is located on www.flashguru.co.uk server and 'b.swf' is located on www.macromedia.com server, for 'a.swf' to be able to access the contents of 'b.swf', 'b.swf' has to make a call to the allowDomain command as follows:

System.security.allowDomain("http://www.flashguru.co.uk");

The domain can be formatted in numerous ways, the same different formats that the loadVariables, loadVariablesNum, xml.load and loadvars.load methods accept: http://www.domain.com

http://domain.com
domain.com
http://IpAddress

You can pass multiple domains to the method as arguments. This method has been documented in the Macromedia Flash MX ActionScript Dictionary Errata (www.macromedia.com/support/flash/documentation/ flash_mx_errata/flash_mx_errata03.html).

Tip #5: Test Player - System Keys
By default, in the local test player(Control > Test Movie), if you try and press the enter key, to test some code that uses it, your code will not work because the player over-rides the key press as a keyboard shortcut to pause and play the movie, the same goes for the tab key and other important system keys, such as Ctrl, Shift etc... So if you want to test your tabIndexes in the test player, so you can use trace and the debugger, simply select Disable Keyboard Shortcuts from the Control menu (Control > Disable Keyboard Shortcuts) and your code will now recieve the key presses. Saves me a lot of faffing around! Think this is something else I was slow on, these little fine details just fly over my head.

About Guy Watson

Guy Watson (aka FlashGuru) has been a well-recognized figure in the Flash community for around four years, supporting the community with tutorials and source files, moderating the large Flash community forums, and running his own Flash resource Web site - FlashGuru's MX 101. Guy was one of the two developers that created the award-winning zoom interface for Relevare and now works for Endemol UK, the creative force behind reality television, producing programs such as Big Brother and The Salon. Guy now spends most of his time developing Flash games and applications for high-profile clients such as Channel 5 Television, Ladbrookes, and UK Style.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.