07Aug Flash Tutorial: Flash Stage Size
Recently stumbled onto a blog post that pointed out the fact that you could use loaderInfo.width/height properties in junction with determining the center of the stage. This information helps a lot as I have found that IE6 will sometimes not report the correct size of the SWF in the browser on the stage properties .width or .stageWidth for example.
- stage.width + stage.height – the size of the content on the stage.
- stage.stageWidth + stage.stageHeight – that dimensions of the monitor the flash player is currently consuming
- loaderInfo.width + loaderInfo.height – that of the Fla’s publish settings
06Aug Flash TOTD: Reverse loop with increment iterator
This can be done several ways… here are two of the faster performance-wise ways for this:
var maxNum:int = 5;
var inverse_i:int;
for(var i:int=maxNum; i => 0 ; i--) {
inverse_i = maxNum - i;
trace(inverse_i);
}
// or you can do this:
var inverse_i:int;
for(var i:int=5; i => 0 ; i--) {
trace(inverse_i);
inverse_i++;
}
05Aug Flash: Creation of general children
In the event of making new children, especially like library movieclips, you could create a generic function that receives the class reference for the movieclip you wish to create. For the below example, let’s say in your library is a RedBox linked movieclip with a variety of other movieclips like it that all need to be created the same way:
addChild( create(RedBox) );
function create(ObjectType:Class):MovieClip{
// Adding "as MovieClip" tells Flash that ObjectType will be
// some kind of MovieClip derived class.
var newMC:MovieClip = new ObjectType() as MovieClip;
// Add new event listeners to newMC
// Add logic or variable settings like X and Y
// returns the newMC to be added to the stage.
return newMC;
}
The benefit is you can dynamically create objects that all get setup the same way… the function does not care what type of movieclip needs to be created just as long as it’s a type of movieclip.
01Aug Flash TOTD: inline functions
This is useful when performing a small quick function that perhaps handles an event listener callback.
var onClickNavAway:Function = function(e:Event) {
navigateToURL(new URLRequest("link.html"),"_self");
}
addEventListener(MouseEvent.CLICK, onClickNavAway);
31Jul Flash Tip of the Day
I am going to try to post something code related everyday (maybe except for the weekend). So today I will cover a super easy tip:
When setting the same property on different objects, you can same time by instead of doing this:
movieClip1.visible = false;
movieClip2.visible = false;
movieClip3.visible = false;
Do This:
movieClip1.visible=movieClip2.visible=movieClip3.visible=false;
Easy, huh?
