Tag Archive: object


Here, I have made some code stuff which could create object looping and can access each object’s property from outside of loop

// importing reated files
import flash.display.Sprite;
import flash.text.TextField;

// Varial declearation
var answer:Array=new Array();
var ansGroup:Array=new Array();
var options:Sprite=new Sprite();

answer[0]=[“nepal”,”china”,”bhutan”,”usa”];
answer[1]=[“Lichi”,”mango”,”banana”,”apple”];
answer[2]=[“sunday”,”monday”,”tuesday”,”saturday”];
answer[3]=[“cat”,”lion”,”monkey”,”donkey”];

for(var i:Number=0; i<4; i++){
// making object
var myTextField:TextField=new TextField();

// Setting property of created object
myTextField.x=i*130;
myTextField.y=25;
myTextField.width=120;
myTextField.height=25;
myTextField.text=answer[0][i];
myTextField.border=true;

// put into ansGroup Array
ansGroup.push(myTextField);

// put into displaycontainer options
options.addChild(myTextField);

}
// Setting displaycontainer property of x and y position
options.y=100;
options.x=25;

// displaying displayContainer
addChild(options);

Overlap display Object in AS3

This tutor is about overlapping display object to each another. Here, I have three files. Ball.as

Ball.as:
here, we have class of circle shape object

BallSeq.as:
It generates circle ball with different color and set sequence

myFlash.fla
here, we need to mention class BallSeq

Ball.as

package {
import flash.display.*;
import flash.text.*;
public class Ball extends Shape{
public var xPos:Number;
public var yPos:Number;
public var radius:Number;
public var color:uint;

public function Ball(xInput:Number,yInput:Number,rInput:Number,colorInput:uint) {
var xPos=xInput;
var yPos=yInput;
var radius=rInput;
var color=colorInput;
this.graphics.beginFill(color);
this.graphics.drawCircle(xPos,yPos,radius);
}
}
}

Here, we have made Ball Class constructor with argument x postion, y position, radius, color

BallSeq.as

package{

import flash.display.Sprite;
import flash.events.MouseEvent;
public class BallSeq extends Sprite {

public var container2:Sprite=new Sprite();
public var blackBall:Sprite=new Sprite();
public var redBall:Sprite=new Sprite();
public var blueBall:Sprite=new Sprite();
public var greenBall:Sprite=new Sprite();

public function BallSeq(){

// Black Ball
blackBall.addChild(new Ball(100,100,30,0x000000));
blackBall.name="blackBall";
//addChild(blackBall);

// Green Ball
greenBall.addChild(new Ball(130,140,30,0x29990b));
greenBall.name="greenBall";
//addChild(greenBall);

// Red Ball
redBall.addChild(new Ball(130,90,30,0xff0000));
redBall.name="redBall";
//addChild(redBall);

// blue Ball
blueBall.addChild(new Ball(150,100,30,0x0000ff));
blueBall.name="blueBall";

container2.addChild(blueBall);
container2.addChild(redBall);
container2.addChild(blackBall);
container2.addChild(greenBall);

container2.swapChildren(blackBall,redBall);

var i:Number=0;
while(i<container2.numChildren){
container2.getChildByName(container2.getChildAt(i).name).addEventListener(MouseEvent.CLICK,putFront);
i++;
}

this.addChild(container2);

}

public function putFront(event:MouseEvent){
container2.setChildIndex(container2.getChildByName(event.target.name),container2.numChildren-1);

}

}

}