Saturday, 31 January 2015

FOR AND LOOP




---------------------------------------------------------------------------------------------------------------
READ MORE:
https://www.youtube.com/watch?v=OkG_ublHhik
http://www.dakmm.com/?tag=loop
ARRAY AND LOOP FUNCTION AND CREAT CHILDS IN AS3
https://www.youtube.com/watch?v=ZOnIHNfskwg

http://kirill-poletaev.blogspot.co.uk/2010/07/how-to-create-calendar-using-only.html http://www.kirupa.com/forum/showthread.php?327541-AS2-AS3-adding-MC-s-to-a-container-MC

-----------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE IN AS3  SET  MOVIE CLASS
rs = new rs();
-----------------------------------------------------------------------------------------------------------
var redSquare:rs = new rs();
var test:int=Math.floor(stage.stageWidth/redSquare.width)
for (var i:Number = 0; i < test; i++){
redSquare = new rs()
redSquare.x = i* redSquare.width
redSquare.y = i* redSquare.height
addChild(redSquare)
}
-----------------------------------------------------------------------------------------------------------------
FOR USE EXTAR SPACING IN BOX CHANGE UPPER CODE WITH  BELOW CODE
----------------------------------------------------------------------------------------------------------------

var i =int ;

var redSquare:rs = new rs();

var timesFitInWidth:int= Math.floor(stage.stageWidth/redSquare.width);
var extraWidth:Number = (stage.stageWidth/redSquare.width) - timesFitInWidth ;

var gapX:Number = (extraWidth / timesFitInWidth ) * redSquare.width ;
var spacingX: Number = redSquare.width + gapX

var timesFitInHeight:int= Math.floor(stage.stageHeight/redSquare.height);
var extraHeight:Number = (stage.stageHeight/redSquare.height) - timesFitInHeight ;

var gapY:Number = (extraHeight / timesFitInHeight ) * redSquare.height ;
var spacingY: Number = redSquare.height + gapY;

for ( i = 0 ; i < timesFitInWidth; i++ )
{

redSquare  = new rs();
redSquare.x = ( redSquare.width /2.0 ) + (gapX / 2.0) + ( i * spacingX );
redSquare.y = redSquare.height /2.0 ;
addChild(redSquare);

}



-------------------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE
http://resolvedqs.com/tube/ZOnIHNfskwg/array-and-loop-function-and-create-childs-in-as3
https://www.youtube.com/watch?v=ZOnIHNfskwg
http://textuploader.com/GSzGX
--------------------------------------------------------------------------------------------------------------------


var A1 = new Array()//XXXXXXXXXXXXXXXXXXXXXXXX
for(var A2:Number = 0;A2<6;A2++){
var A3:MovieClip = new BALL();
A1[A2] = A3;//XXXXXXXXXXXXXXXXXXXXXXXX
A3.y = 10//XXXXXXXXXXXXXXXXXXXXXXXX
A3.x += 10+(A2* 60)//XXXXXXXXXXXXXXXXXXXXXXXX
addChild(A3)}//XXXXXXXXXXXXXXXXXXXXXXXX
//*******************************************************************************//
//*******************************************************************************//
var A1 = new Array()//XXXXXXXXXXXXXXXXXXXXXXXX
for(var A2:Number = 0;A2<6 * Math.random();A2++){
var A3:MovieClip = new BALL();
A1[A2] = A3;//XXXXXXXXXXXXXXXXXXXXXXXX
A3.y = 10//XXXXXXXXXXXXXXXXXXXXXXXX
A3.x += 10+(A2* 60)//XXXXXXXXXXXXXXXXXXXXXXXX
addChild(A3)}//XXXXXXXXXXXXXXXXXXXXXXXX
//*******************************************************************************//
//*******************************************************************************//
myButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(evt:MouseEvent):void {
var A1 = new Array()//XXXXXXXXXXXXXXXXXXXXXXXX
for(var A2:Number = 0;A2<6 * Math.random();A2++){
var A3:MovieClip = new BALL();
A1[A2] = A3;//XXXXXXXXXXXXXXXXXXXXXXXX
A3.y = 10//XXXXXXXXXXXXXXXXXXXXXXXX
A3.x += 10+(A2* 60)//XXXXXXXXXXXXXXXXXXXXXXXX
addChild(A3)}}//XXXXXXXXXXXXXXXXXXXXXXXX
//*******************************************************************************//
//*******************************************************************************//


----------------------------------------------------------------------------------------------------------------------
FOR LOOP AS3 ADD CHILD MAKE COLUMN ROW

DOWNLOAD SOURCE:
http://bit.ly/1zcsI3f
--------------------------------------------------------------------------------------------------------------------

FOR AND LOOP AS3




----------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW  CODE AND FOLLOW METHOD
http://textuploader.com/6ob9
---------------------------------------------------------------------------------------------------------------

//https://www.youtube.com/watch?v=M678T8dgE5s
// MAKE MOVIE CLIP SYMBOL WITHOUT INSTANCE NAME
// MOVIE CLIP SYMBOL HEIGHT & WIDTH =50 PX
// MOVIE CILP SYMBOL  XY POSITION SHOULD BE ZERO
// SET MOVIE  CLIP SYMBOL CLASS NAME : tile
var xPos = 0;
var yPos = 0;
for (var i = 1;i<89;i++){
var myTile = new tile();
addChild(myTile)
myTile.x = xPos
xPos += 50
myTile.y = yPos
if(xPos==550){
xPos= 0 ;yPos +=50
}}

----------------------------------------------------------------------------------------------------------------------
ROW AND COLUMN IN AS2
 COPY AND PASTE CODE FOR FRAME ACTION SCRIPT
https://www.youtube.com/watch?v=z0RX1T99MPI
DOWNLOAD SOURCE FILE
http://bit.ly/1EgTbij
----------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------

//MAKE 3 MOVIE CLIPS BTN ENEMY SPOT AND DRAW TEXT BOX
//GIVE INSTANCE NAME FOR BTN "btn"
//GIVE INSTANCE NAME FOR ENEMY "enemy"
//SET IDENTIFIER NAME FOR SPOT "spot"
//GIVE INSTANCE NAME FOR TEXT BOX "msg"

stop();
var gridMC:MovieClip = this.createEmptyMovieClip("gridMC", 1);
enemy.swapDepths(1000)
nrCol = 9;
nrRow = 9;
gridId = 0;
marginLeft = 50;
marginTop = 70;
createGrid();
function createGrid() {
for (i=0; i<nrRow; i += 1) {
for (j=0; j<nrCol; j += 1) {
mc = gridMC.attachMovie("spot", "spot"+gridId, gridId);
mc._width = mc._height=44;
mc._x = marginLeft+(mc._width*(j));
mc._y = marginTop+(mc._height*(i));
mc.onRollOver = function() {
trace(this._name)}
gridId++;
mc.gid.text = gridId}}}

function placeToSpot() {
var randomSpot:Number = Math.floor(Math.random()*9);
enemy._x = gridMC["spot"+randomSpot]._x;
enemy._y = gridMC["spot"+randomSpot]._y;
msg.text = "random spot is "+gridMC["spot"+randomSpot]._name+" mc, grid number "+(randomSpot+1);
}
btn.onRelease = function() {
placeToSpot();
}

------------------------------------------------------------------------------------------------------------------
ADD CHILD EXAMPLE
--------------------------------------------------------------------------------------------------------------------
//http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b8ea63-7fee.html
var SymbolClass:ClassBox = new ClassBox();
stage.addChild(SymbolClass);
Mc1.addChild(SymbolClass);
------------------------------------------------------------------------------------------------------------------
ADD CHILD WITH BUTTON EXAMPLE
-----------------------------------------------------------------------------------------------------------------
//http://stackoverflow.com/questions/1500017/stage-addchild-and-layering
btn1.addEventListener(MouseEvent.CLICK, friendMaker);
function friendMaker(evt:MouseEvent):void {
var newFriend:Teddy = new Teddy();
newFriend.x = Math.random()*stage.width;
newFriend.y = Math.random()*stage.height;
stage.addChild(newFriend);
stage.addChild(btn1);
}
-------------------------------------------------------------------------------------------------------------------
MAKE TEN MOVIE CLIPS
------------------------------------------------------------------------------------------------------------------
https://books.google.co.uk/books?id=9xqBU_BlOkoC&pg=PT104&dq=mascot+addchild&hl=en&sa=X&ved=0ahUKEwiEoI7MmKzLAhVE2xoKHYhjCSQQ6AEIHDAA#v=onepage&q=mascot%20addchild&f=false
mascot addchild
-------------------------------------------------------------------------------------------------------------------
for (var i=0; i<10; i++) {
var mascot:Mascot = new Mascot();
mascot.x = 50*i + 50;
mascot.y = 100;
mascot.scaleX = .5
mascot.scaleY = .5
addChild(mascot);
}

----------------------------------------------------------------------------------------------------------------------
FOR LOOP
http://www.dakmm.com/?tag=loop
----------------------------------------------------------------------------------------------------------------------
//http://www.dakmm.com/?tag=loop
//MAKE BUTTON WITH INSTANCE NAME "Btn1"
//MAKE TEXT BOX WITH INSTANCE NAME "T1"
//MAKE TEXT BOX WITH INSTANCE NAME "T2"
T1.text="10";
Btn1.addEventListener(MouseEvent.CLICK, fLoop);
T1.restrict = "0-9";
T1.maxChars = 3;
function fLoop(event:MouseEvent):void {
T2.text="";
var vString:String = T1.text;
var vExample:Number = Number(vString);
for (var i:Number=0; i< vExample; i++)
{T2.appendText([i]+", ")
}
}
-----------------------------------------------------------------------------------------------------------------------
AS2 AS3 LOOP
------------------------------------------------------------------------------------------------------------------------


------------------------------------------------------------------------------------------------------------------------
AS2 CODE:
https://www.youtube.com/watch?v=xmi0TxJvbEQ
https://www.youtube.com/watch?v=czK4XrYVCMg
//AS2 CODE KEY BOARD ENTER KEY
var myListener:Object = new Object();
Key.addListener(myListener);
myListener.onKeyDown = function (){
if(Key.getAscii() == Key.ENTER){
------------------------------------------------------------------------------------------------------------------------

for(

var Num1:Number = 0;

Num1 < 5;

Num1++

)

{

trace(Num1);
Txt1.appendText([Num1]+", ")

// TRACE LOOP IN AS2
Txt1.text = (Num1)

}


Btn1.onRelease= function(){


Txt1.text="";

// IF TEXT BOX EQUAL TO NUM1

var Num1:String = NumTxt.text;

// IF TEXT BOX EQUAL TO NUM1

var Num2:Number = Number(Num1);

for(

var i:Number = 0;

i < Num2;

i++

)

{

Txt1.appendText([i]+", ")

// TRACE LOOP IN AS2
Txt1.text = i

}

}

ClearBtn.onRelease= function(){
Txt1.text="";
}




------------------------------------------------------------------------------------------------------------------------
AS3 CODE:
https://www.youtube.com/watch?v=xmi0TxJvbEQ
https://www.youtube.com/watch?v=czK4XrYVCMg

//AS3 CODE KEY BOARD ENTER KEY
NumTxt.addEventListener(KeyboardEvent.KEY_DOWN,handler);
function handler(event:KeyboardEvent){
------------------------------------------------------------------------------------------------------------------------

for(

var Num1:Number = 0;

Num1 < 5; 

Num1++

)

{

trace(Num1);
Txt1.appendText([Num1]+", ")

}


Btn1.addEventListener(MouseEvent.CLICK,BTN1)
function BTN1(e:MouseEvent){

Txt1.text="";

// IF TEXT BOX EQUAL TO NUM1

var Num1:String = NumTxt.text;

// IF TEXT BOX EQUAL TO NUM1

var Num2:Number = Number(Num1);

for(

var i:Number = 0;

i < Num2; 

i++



{

Txt1.appendText([i]+", ")

}

}

ClearBtn.addEventListener(MouseEvent.CLICK,BTN2)
function BTN2(e:MouseEvent){
Txt1.text="";
}

---------------------------------------------------------------------------------------------------------------------
LOOP GENERATOR AS3
http://qczma.com/blog/random-numbers-generator-as3
http://stackoverflow.com/questions/21731819/new-to-actionscript3-making-calculator-and-stuck
---------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------
CODE:
---------------------------------------------------------------------------------------------------------------------

Btn1.addEventListener(MouseEvent.CLICK,BTN1)
function BTN1(e:MouseEvent){
Txt1.text="";
var EndNumber:Number = Number(EndTxt.text)
//http://stackoverflow.com/questions/21731819/new-to-actionscript3-making-calculator-and-stuck
var DifNumber:Number = Number(EndTxt.text) - Number(StartTxt.text)
for(
var StartNumber:Number = Number(StartTxt.text);
StartNumber < EndNumber;
StartNumber ++
)
{
Txt1.appendText([StartNumber]+",")
}
Txt2.text = String(DifNumber)
}
ResetBtn..addEventListener(MouseEvent.CLICK,Rn)
function Rn(e:MouseEvent){
Txt1.text="";
Txt2.text="";
StartTxt.text = "";
EndTxt.text = "";
}










EmoticonEmoticon