Flex easing classes used by effects

The mx.effects.easing package contains the easing classes used by effects.

Classes

Back
Bounce
Circular
Cubic
Elastic
Exponential
Linear
Linear
Quartic
Quintic
Sine

Method

easeIn
easeInOut
easeNone
easeOut

Example

<mx:Move yFrom=”-10″ easingFunction=”Linear.easeOut” duration=”1000″ />

AS 3.0 Loader

var request:URLRequest = new URLRequest(”mandar.swf”);
var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

function loadProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
trace(”Loading: “+percentLoaded+”%”);
}
function loadComplete(event:Event):void {
trace(”Complete”);
}

loader.load(request);
addChild(loader);


AS3.: can stop net connection

Previous versions of the Flash player could not close connections to the internet once a download into the player has started. For example if you start loading 30mb and sudenely you need to stop and handle differnt request. previous version couldn’t do it.

In Flash Player 9, using ActionScript 3, you can now stop connections and abort loading requests made by the player. see the following code

var loader:Loader = new Loader(); var request:URLRequest = new URLRequest("image.jpg"); loader.load(request); addChild(loader); // abort loading if not done in 3 seconds var abortID:uint = setTimeout(abortLoader, 3000); // abort the abort when loaded loader.contentLoaderInfo.addEventListener(Event.COMPLETE, abortAbort); function abortLoader(){     try {         loader.close();     }catch(error:Error) {} } function abortAbort(event:Event){     clearTimeout(abortID); }

Flash: Dynamically Change Frame Rate

New to ActionScript 3.0 is the ability to dynamically change the frame rate at which your file plays at runtime. The default frame rate of a Flash movie is 12 frames per second, and we can change dynamically increase or decrease frame rate run time. following example shows how to change frame rate runtime.

Create two buttons on stage and give name “faseter” and “slower”.

faster.addEventListener(MouseEvent.CLICK, onFasterClick, false, 0, true);
slower.addEventListener(MouseEvent.CLICK, onSlowerClick, false, 0, true);

function onFasterClick(evt:MouseEvent):void {
stage.frameRate += 5;
trace(stage.frameRate);
}
function onSlowerClick(evt:MouseEvent):void {
if (stage.frameRate > 5) {
stage.frameRate -= 5;
}
trace(stage.frameRate);
}


AS3.0: Run time Scale nine in Flash

Run time scale is possible in AS3.0 for Flash. see the following example.

Steps:

1. Create new Sprite

var sp:Sprite = new Sprite();

2. Fill as corner rediol rectangular shape

with(sp.graphics)
{
lineStyle(1,0×000000,1,true);
beginFill(0xff0000,.5);
drawRoundRect(0,0,100,50,15);
endFill();

}

3. set position into the stage.

sp.x = sp.y = 50;

4. Add into the stage

addChild(sp);

5. Set the scale nine grid

var slice9:Rectangle = new Rectangle(15,15,70,20)
sp.scale9Grid = slice9;

6. Change the shape of the rectangle onEnter event

addEventListener(Event.ENTER_FRAME,onLeave,false,0,true);

function onLeave(event:Event):void
{
sp.width = Math.max(mouseX – sp.x,31);
sp.height = Math.max(mouseY – sp.y,31);
}


AS3.0: Load image class

Load external image in to swf file.

package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;

public class loadImg extends Sprite
{

public function loadImg()

{

init()
}

private function init():void
{
var loader:Loader = new Loader();
addChild(loader);
loader.load(new URLRequest(”image.jpg”));

}
}

}

Flash AS3.0, XML and E4X

ActionScript 3.0 changes things quite significantly. The good news is that the new approaches make life much easier.  ActionScript 3.0 includes completely new XML functionality based on the E4X specification

In ActionScript 3.0, can target content in an XML object by using methods of the XML class to write E4X expressions.

Here I am giving an example. how to parse data through using different methods.

code:

package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLLoader;

import flash.net.URLRequest;public class main extends Sprite {

private var xmlMessage:XML;
private var xmlLoader:URLLoader;
private var xmlRequest:URLRequest;

public function main() {
init();
}

private function init() {

addChild(menuText);

var strXMLPath:String = “myXML.xml”;xmlLoader = new URLLoader();

xmlLoader.addEventListener(Event.COMPLETE,completeHandeler);

xmlLoader.load(new URLRequest(strXMLPath));

}

private function completeHandeler(event:Event):void {

xmlMessage = XML(event.target.data);

mText.text = xmlMessage.menuTitle;
}

}


AS 3.0 : set Interval

Set interval in AS3.0

var timer:Timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER, onTimer,false,true,false);
timer.start();
function onTimer(evt:TimerEvent):void{
hand.rotation +=5;

}


Load SWF into MovieClip in AS3

Loading external swf file is essay in AS2.0 but it is not so essay in AS3.0, to load swf file need to define loader class and URL path pointing to the external swf.

var swfLoader:Loader = new Loader();

holderMC.addChild(swfLoader);

var bgURL:URLRequest = new URLRequest(”loadSWF_File.swf”);

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);

swfLoader.load(bgURL);

function loadProdComplete(e:Event):void {

trace(”file loaded”);

}


Action script 3.0 : Depth Mantain

Previous version in As2.0 depth maintain by swapDepth() method, but in AS3.0 the method getNextHighestDepth is no longer supported. Here’s how to swap depth in Actionscript 3. 0 Use the setChildIndex() method to changes the position of an existing child in the display object container with the instances name.

Where In AS3.0 set the depth automatically through indexing like addChild(car) maintain on 0 depth while car.addChild(mirror) mirror pushed over car. Maintain depth by addChildAt() method. for example addChildAt(mirror, car).