Short Tag – Web Development Blog

Entries for the ‘Action Script 3’ Category

As3 mouseChildren – mouse events and relation with MovieClip children

Let’s take the following example:
We have a toolbar (MovieClip) that contains other movieclips and buttons or other display objects. If I want to create an MOUSE_OVER, MOUSE_OUT event listener on the toolbar, every time you move your mouse over a children of the toolbar a MOUSE_OUT and a MOUSE_OVER event is triggered. This can cause [...]

SetFocus on an object with AS3

Amongst the many changes from AS2 to As3 is the way we set the focus.
In AS2 you can set the focus using the setFocus function on an object.
In AS3 you set the focus using the “focus” property of a container object(stage, movieclip, etc…).
Example:

stage.focus = txtField;

where ‘txtField’ is a textField on the stage.

AS3 get file contents, load and work with XML

As3 has a few classes that ease our work with external files (for example with XMLs).
First I will show you how to load an external file:

var file:string = "myfile.txt";
var ur:URLRequest = new URLRequest(file);
var ul:URLLoader = new URLLoader();
ul.addEventListener(Event.COMPLETE, loaded);
ul.load(ur);

function loaded(e:Event):void
{
var str:String = e.target.data;
trace(‘Loaded data is:’+str);
}

In the example above str variable will hold the content of a [...]

ActionScript 3 getURL()

Among the big changes in AS3 is the change of getURL() function. This function has been eliminated from AS3, since this language has became an Object Oriented programming language and it followes the rules of ECMAScript.
In AS2 to open a url (to create a link in flash) we had to use getURL function.
In AS3 we [...]

AS3 random range

As3’s Math.random() function returns a random decimal number between 0 and 1. Here is a function that uses Math.rand() to generate a random number within a specified range:

function rand(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum – minNum + 1)) + minNum);
}

This function return a random number within a range. It is much like PHP’s rand() function.
Usage:

var i:Number [...]

AS3 string replace function

function replace(input:String, replace:String, replaceWith:String):String
{
var sb:String = new String();
var found:Boolean = false;

var sLen:Number = input.length;
var rLen:Number = replace.length;

for (var i:Number = 0; i < sLen; i++)
{
if(input.charAt(i) == replace.charAt(0))
{
found = true;
for(var j:Number = 0; j < rLen; j++)
{
if(!(input.charAt(i + j) == replace.charAt(j)))
{
found = false;
break;
}
}

if(found)
{
sb += replaceWith;
i = i + (rLen – 1);
continue;
}
}
sb += input.charAt(i);
}
return sb;
}

This function is [...]

Stage.align in Flash

Stage.align property sets the 0,0 coordinates of the Stage to a certain position.
For example:
Stage.align = “TL”; – sets the 0,0 coordinates to the top-left part of the Stage.
Stage.align = “CC” or Stage.align=”” – the default position is in the center of the Stage.
Stage.align property values:

Value
Vertical
Horizontal

“T”
top
center

“B”
bottom
center

“L”
center
left

“R”
center
right

“TL”
top
left

“TR”
top
right

“BL”
bottom
left

“BR”
bottom
right

C – use C in combination where you need to represent [...]

Buttons not working in fullscreen (Flash)

Another “bug” I found in Flash. This time in AS2.
Probably some of you noticed that they cannot click on their buttons in fullscreen mode in some browser like: Chrome, Opera or Firefox.
I cannot explain why this happens but I have the solution.
This problem appears only if you set fullscreen-mode from onPress event-handler, with onRelease everything [...]

Flash CS4 AS3 FLVPlayBack Component indicator not moving

Flash CS4 AS3 FLVPlayBack Component indicator not moving?
FlvPlayBack Component indicator is not moving if the isLive field is set to true, it just simply stand there and the movie is playing without problems.
So you just have to:
fpb.isLive = false;
If you need to use it with isLive I don’t know what to do, if you know [...]

FLASH CS4 AS3 TextField width not returned correctly?

FLASH CS4 AS3 TextField width not returned correctly?
You have to set the textfield’s multiline property to false else the field will be considered a multiline textfield and this will result in incorrect calculations.
Example:
textField.multiline = false;
I’ve seen this problem in Flash CS4 with AS3. It may be present in other versions too.
AS3 Freaks me out [...]