Closing Down Flash Library
I used to maintain the site flashlibrary.co.uk but haven’t updated in years so have closed it down.
On of the section of the sites contained a number of quick flash tips which are below. Most of the tips are more appropriate to actionscript 2 though.
Embed fonts’ styles aren’t included
Bold and italic styles are not included with embed fonts. They need to be included separately.
Don’t overwrite _name in MovieClip classes
Careful not to use the property ‘_name’ in any of your movieClip classes.
Some useful ASDT and Eclipse shortcuts
Learn the shortcut keys for Eclipses and ASDT(Actionscript Development Tool). I would recommend you try to learn as many as possible but the following are particularly interesting.
* [ALT]+/ - Auto-complete * F3 - Follow method * [CTRL]+[SPACE]
Give attached MovieClips unique names and depths
Give MovieClip instances unique depths and unique names to avoid accidentally overwriting other MovieClip instances.
URLs with // wont work in a browser
The flash authoring environment will let you download images and other files with two slashes(//) in the URL. However when the swf is run in a browser it wont load.
Careful with package names
Don’t give package names the same name as their class i.e. layout.Layout.
Keeping DataType with classes that extend MovieClip
My preferred method for treating a MovieClip like a class is as follows.
class MyButton extends MovieClip{
private var _depth:Number = 0;
private function MyButton(){
}
/**
*
*/
public static function create(target:MovieClip,id:String,depth:Number,initObj:Object):MyButton{
initObj = initObj||{};
var name:String = id+depth;
// Attach MovieClip
Object.registerClass(id,MyButton);
return MyButton(target.attachMovie(id,name,depth,initObj));
}
}
Use this.gotoAndPlay() not gotoAndPlay()
Put ‘this’ in front of gotoAndPlay() methods called within a class that extends ‘MovieClip’.
Flipping MovieClips with Actionscript
You can use _xscale and _yscale to flip vertically and horizontally if you use a negative value.
Actionscript and IDE can use different Positions
The position of MovieClips dragged on to the stage is based on their dimensions. When attached with Actionscript it’s based on the movieClips origin. For example if I have a simple box shape within a MovieClip. If I open up the MovieClip there should be a box shape. If the position of the shape was _x = -10 and y = 0 so the box is 10 pixels left of the origin(0,0). Were I do drag this MovieClip to the stage and set it’s position to (0,0) it would line up perfectly with stages top left corner despite actually being offset. This being the case I might assume that in order to attach the box movieClip to appear in the same position I would set it’s _x and _y properties to 0. This would wrong since attached MovieClips are attached based on there origin location. In this case the box would appear 10 pixels to the left of stage. This is why it’s good practice to always have any move clips aligned to the origin so that no content goes beyond the x and y boundaries.
Use swapDepths() to remove MovieClips
MovieClips need to have a positive depth to be removed.
Communicating between SWF
When using LocalConnection remember that the SWF(Shockwave Flash) should be the same player version. Well I found that between 7 and 8 it didn’t work.
If you use Flex and SVN(Subversion) you will need to install “subclipse”:http://subclipse.tigris.org/install.html or something similar. If you don’t ever time you publish your Flex application the .swn files will all be shuffled about. You need to install version 1.0.5 for Flex. This will mean unchecking “Show the latest version of a feature only”. Otherwise you’ll like get the error “Subclipse (1.2.0) requires plug-in “org.eclipse.core.resources (3.2.0)”, or later version.” or similar.
Don’t Rely on Stage.width and Stage.height
Stage.width and Stage.height sometimes return a value of 0 when run in IE(Internet Explorer) .
If you are extending components and it doesn’t appear to be working remember to check whether the export settings are appropriate for the component i.e. if your actionscript classes arn’t exported on the first frame remember to take the ‘Export in first frame’ option off your component. This proved particularly bothersome for the FLVPlayback component since you wont see the component whether it is included or not. Not unless you load a FLV(Flash Video) file onto it.
When loading in a new line character with XML in flash, flash will automatically substitute the \n to \\n. This will mean it wont used as a newline character and will simply be show as normal text. To overcome this you need to replace all occurrences of \\n with \n.
desc = desc.split(’\\n’).join(’\n’);
some_tf.text = desc;
Where desc is the string to be changed.
When loading in swf I have found it’s better to have the swf of the same flash player. Not really a firm rule, but from experience somethings stop working for no apparent reason.
Test tabIndex in a browser
Disable keyboard shortcuts when testing tab index.
It’s generally preferable not to use *Stage.width* and *Stage.height*. You are better just using constants as the actual value is often read as 0 in IE(Internet Explorer) . If you have to use because you are creating a liquid layout that fills the screen you should include a check to ensure that *Stage.width* and *Stage.height* aren’t 0.
I have noticed some very strange caching issues when using Runtime shared assets. It becomes impossible to clear the cached elements.
I got the following error from Flex 2 when debugging.
C:\WINDOWS\system32\Macromed\Flash\Flash9d.ocx
Flex Builder cannot locate the required debug version of the Flash Player. You may need to install the debug version of Flash Player 9.0 or reinstall Flex Builder. Do you want to try to debug with the current version?
I’m not sure why the problem occured but I had recently installed flash 8 as well as both Firefox and IE7(Internet Explorer 7) so it was possibly any of the above. To resolve it uninstall flash and then run ‘Install Flash Player 9 AX.exe’ which you will find in the player folder of your flex installation. For example mine is located at the following address.
C:\Program Files\Adobe\Flex Builder 2\Player\debug
Running this should re-install a debugging version of the flash player and hopefully resolve the problem.
Super constructors are always called
The super constructor of a class is always called. Regardless of whether a super() method is included.
Flash detection doesn’t work on IE7
If flash works in IE but the flash detection doesn’t work then you need to uninstall and re-install flash.
Include the build version in flash detection
Remember to include the build version in your flash detection. Otherwise you flash might not work on a number of computers(there are differences between the builds).