AS3 remedy to overcome removed / replaced AS2 terms

on()/onClipEvent():
AS2:

on (release) {
this._parent.gotoAndPlay(1);
}

AS3:

replayBtn.addEventListener(MouseEvent.CLICK, replayBtnClickListener);
function replayBtnClickListener (e) {
gotoAndPlay(1);
}

or

replayBtn.addEventListener(MouseEvent.CLICK, function (e) {
gotoAndPlay(1);
});

Delegate Class:
The Delegate Class of AS2, is more simpler to write in AS3 as like the example below:
AS2:

myButton.addEventListener(“click”, Delegate.create(this, someMethod));
Delegate.create(this, someMethod)

AS3:

myButton.addEventListener(“click”, someMethod);

loadMovie

AS2:

theClip.loadMovie(“animation.swf”);

AS3:

var l:Loader = new Loader();
l.load(new URLRequest(“animation.swf”));
theParent.addChild(l);

Controlling Parent Movie Clips
AS2:

this._parent.play();

AS3:

MovieClip(this.parent).play();

or

this.parent[“play”]();

Removal of getURL()
AS2:

getURL(“https://nsdevaraj.wordpress.com/”);

AS3:

navigateToURL(new URLRequest(“https://nsdevaraj.wordpress.com/));

AS3 class to use getURL:

package {
import flash.net.*;

public function getURL (url:String,
window:String = “_self”):void {
var u:URLRequest = new URLRequest(url);
navigateToURL(u, window);
}
}

Usage:

getURL(“https://nsdevaraj.wordpress.com/”);

or

getURL(“https://nsdevaraj.wordpress.com/”, “_blank”);

createTextField:
AS2

someClip.createTextField(“t”,0, 0, 0, 100, 100);
someClip.t.text = “Hello world”;

AS3

var t:TextField = new TextField();
t.text = “Hello world”;

eval Objects:
AS2:

for (var i = 0; i < 10; i++) {
parentClip.attachMovie(“Animation” + i, “instance” + i, i);
}

AS3:

var Symbol:Object;
for (var i:int = 0; i < 10; i++) {
Symbol = getDefinitionByName(“Animation” + i);
parentClip.addChild(new Symbol());
}

attachMovie:
AS2:

parentClip.attachMovie(“Animation”, “instance” , 1);

AS3:

package {
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
import flash.utils.getDefinitionByName;

public function addChildFromLibrary (parent: DisplayObjectContainer,
symbolName:String,
depth:int = -1): DisplayObject {
var Symbol = getDefinitionByName(symbolName);

if (depth < 0) {
return parent.addChild(new Symbol());
} else {
return parent.addChildAt(new Symbol(), depth);
}
}
}

Usage:

addChildFromLibrary(parentClip, “Animation”);

duplicateMovieClip()
AS2:

duplicateMovieClip (circle, “circle1”,  1);

AS3:

package {

import flash.display.DisplayObject;
import flash.geom.Rectangle;
import flash.system.Capabilities; // version check for scale9Grid bug

public function duplicateDisplayObject(target: DisplayObject, autoAdd:Boolean = false): DisplayObject {
var targetClass:Class = Object(target).constructor;
var duplicate: DisplayObject = new targetClass() as DisplayObject;

// duplicate properties
duplicate.transform = target.transform;
duplicate.filters = target.filters;
duplicate.cacheAsBitmap = target.cacheAsBitmap;
duplicate.opaqueBackground = target.opaqueBackground;
if (target.scale9Grid) {
var rect:Rectangle = target.scale9Grid;

if (Capabilities.version.split(” “)[1] == “9,0,16,0”){
// Flash 9 bug where returned scale9Grid as twips
rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20;
}

duplicate.scale9Grid = rect;
}

// add to target parent’s display list
// if autoAdd was provided as true
if (autoAdd && target.parent) {
target.parent.addChild(duplicate);
}
return duplicate;
}
}

Usage:

var circle1:MovieClip =  duplicateDisplayObject(circle, true);

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: