ActionScript

Dynamic change of a label from a SimpleButton object

To modify a label of a custom made button of type Button (which belongs to the SimpleButton class), assuming that this button is called myLabel, we can do the following:


// we need the Sprite class from the display package and the  TextField class from the text package
import flash.display.Sprite;
import flash.text.TextField;

// we declare the states that we want to modify, read/write proprieties of the SimpleButton class
var aStates:Array = ["upState", "overState", "downState"];

var str:String = "My New Text Label";

Schimbarea dinamica a unui label dintr-un obiect SimpleButton

Pentru a modifica labelul unui buton de tip Button (apartinand clasei SimpleButton) creat de catre noi, presupunand ca acest buton se numeste myLabel, procedam astfel:

// avem nevoie de clasa Sprite din pachetul display si de clasa TextField din pachetul text
import flash.display.Sprite;
import flash.text.TextField;

// declaram starile pe care dorim sa le modificam, proprietati read/write ale calsei SimpleButton
var aStates:Array = ["upState", "overState", "downState"];

var str:String = "My New Text Label";

// parcurgem starile
for each(var _st  

Identifying in the Flash Player in which the SWF file runs

For identifying the type of Flash Player in which the SWF file runs we can use:

// we need the Capabilities class from the package system
import flash.system.Capabilities;

//...

trace(Capabilities.playerType);

Will return:

"StandAlone" for the StandAlone Flash Player
"External" for the version of Flash Player used by the external player or the testing mode of the SWF files
"PlugIn" for the plug-in Flash Player (FireFox and others)
"ActiveX" for the ActiveX Control Flash Player used by Microsoft Internet Explorer (IE)

Changing the color of a MovieClip using ActionScript

Let's say we have a MovieClip called myMovie:


// we need the ColorTransform class from the package geom
import flash.geom.ColorTransform;

// we change its color to red (FF0000)
var myColorTransform:ColorTransform = myMovie.transform.colorTransform;
myColorTransform.color = 0×FF0000;
myMovie.transform.colorTransform = myColorTransform;

myMovie will now be red.

Email validation in ActionScript (AS 2.0 and AS 3.0)

For AS 2.0 you can use the following validation assuming that the email is in the TextField named email:

var myEmail:String = email.text;
if ( (myEmail != "") 
	&& ((myEmail.indexOf("@", 0) < 0)
	|| (myEmail.indexOf(".", 0) < 0)
	|| (myEmail.lastIndexOf("@") < 1 
	|| myEmail.lastIndexOf(".") - myEmail.lastIndexOf("@") < 2 
	|| myEmail.length - myEmail.lastIndexOf(".") < 3)) ) 
{
	// the address isn't valid
} else {
	// the address is valid
}

Schimbarea culorii unui MovieClip folsind ActionScript 3.0

Presupunand ca MovieClipul-ul se numeste myMovie:


// avem nevoie de clasa ColorTransform din pachetul geom
import flash.geom.ColorTransform;

// schimbam culoarea in rosu (FF0000)
var myColorTransform:ColorTransform = myMovie.transform.colorTransform;
myColorTransform.color = 0×FF0000;
myMovie.transform.colorTransform = myColorTransform;

myMovie va fi acum rosu.

Validarea email-ului in ActionScript (AS 2.0 si AS 3.0)

Pentru AS 2.0 este ok urmatoarea validare presupunand ca email-ul se afla in campul denumit email:

var myEmail:String = email.text;
if ( (myEmail != "") 
	&& ((myEmail.indexOf("@", 0) < 0)
	|| (myEmail.indexOf(".", 0) < 0)
	|| (myEmail.lastIndexOf("@") < 1 
	|| myEmail.lastIndexOf(".") - myEmail.lastIndexOf("@") < 2 
	|| myEmail.length - myEmail.lastIndexOf(".") < 3)) ) 
{
	// adresa incorecta
} else {
	// adresa corecta
}

Identificarea tipului de Flash Player in care ruleaza fisierul SWF

Pentru identificarea tipului de Flash Player in care ruleaza fisierul SWF se poate folosi:

// avem nevoie de clasa Capabilities din pachetul system
import flash.system.Capabilities;

//...

trace(Capabilities.playerType);

Va intoarce:

"StandAlone" pentru Flash Player-ul StandAlone
"External" pentru versiunea de Flash Player folosita de player-ul extern sau modul de testare a fisierelor SWF
"PlugIn" pentru Flash Player-ul plug-in de browser (FireFox si altele)

Syndicate content