Tuesday, 20 January 2015

SHUFFLING ARRAY IN AS2


--------------------------------------------------------------------------------------------------------------------
SHUFFLING ARRAY IN AS2
READ MORE:
http://www.kirupa.com/forum/showthread.php?379038-Flash-as2-Can-t-get-this-to-work-Shuffling-an-Array-Plese-Look
Download Source:
http://bit.ly/1usOBv6
--------------------------------------------------------------------------------------------------------------------
FOLLOW INSTRUCTION
CREATE spot_mc MOVIE CLIP AFTER THAT MAKE 9 COPIES OF spot_mc
AND GIVE INSTANCE NAME spot1,spot2,spot3,spot4,spot5,spot6,spot7,spot8,spot9
WITHOUT INSTANCE IDENTIFIER MOVIE NAME
enemy1_mc , enemy2_mc , enemy3_mc , enemy4_mc , enemy5_mc , enemy6_mc , enemy7_mc
enemy8_mc , enemy9_mc










=================================================================
COPY AND PASTE BELOW CODE
https://www.youtube.com/watch?v=mr3lhnBahQk
=================================================================

var enemyArray:Array = ["enemy1_mc","enemy2_mc","enemy3_mc","enemy4_mc","enemy5_mc","enemy6_mc","enemy7_mc","enemy8_mc","enemy9_mc"];
var spotArray:Array = [spot1,spot2,spot3,spot4,spot5,spot6,spot7,spot8,spot9];
for(i=0; i<spotArray.length; i++) {
spotArray[i]._alpha = 40;
}
function shuffleArray(array:Array) {
var i:Number = array.length;
var j:Number = 0;
var temp:Number = 0;
if (i == 0) {
return [0];
}
while (--i) {
j = Math.floor(Math.random()*(i+1));
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
function enemiesPlacement() {
shuffleArray(enemyArray);
shuffleArray(spotArray);
var randomSelection = Math.floor((Math.random() * spotArray.length))+1;
trace("there will be "+randomSelection+ " enemies")
for(i=0; i<randomSelection; i++) {
var spot_mc = spotArray[i];
spider_mc = attachMovie(enemyArray[i], enemyArray[i], _root.getNextHighestDepth());
spider_mc._x = spot_mc._x;
spider_mc._y = spot_mc._y;
trace(enemyArray[i] +" is placed on " + spotArray[i])
}
}
enemiesPlacement()
==============================================================
OR USE THIS CODE
===============================================================

var spotArray:Array = [S1,S2,S3,S4,S5,S6,S7,S8,S9];
var enemyArray:Array = ["E1","E2","E3","E4","E5","E6","E7","E8","E9"];
for(i=0; i<spotArray.length; i++) {
spotArray[i]._alpha = 40;
}
function shuffleArray(array:Array) {
var i:Number = array.length;
var j:Number = 0;
var temp:Number = 0;
if (i == 0) {
return [0];
}
while (--i) {
j = Math.floor(Math.random()*(i+1));
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
function enemiesPlacement() {
shuffleArray(enemyArray);
shuffleArray(spotArray);
var randomSelection = Math.floor((Math.random() * spotArray.length))+1;
trace("there will be "+randomSelection+ " enemies")
for(i=0; i<randomSelection; i++) {
var spot_mc = spotArray[i];
spider_mc = attachMovie(enemyArray[i], enemyArray[i], _root.getNextHighestDepth());
spider_mc._x = spot_mc._x;
spider_mc._y = spot_mc._y;
trace(enemyArray[i] +" is placed on " + spotArray[i])
}}
enemiesPlacement()

-----------------------------------------------------------------------------------------------------------------
FOR  BUTTON AS3 CODE
http://openclassrooms.com/forum/sujet/flash-as3-mouseevent-35957?page=1
----------------------------------------------------------------------------------------------------------------

var  bt: Array  = [bt1, bt2, bt3, bt4, BT5, bt6, bt7, BT8, BT9]
var  functions: Array  = [affLassociation, test];
var  array: Array  = [ "bt1" , "bt2" , "bt3" , "bt4" , "BT5" , "bt6" , "bt7" , "BT8" , "BT9" ];

for ( var  i: int = 0 ; i < 9 ; i ++)
{
   
    TweenMax.to (bt [i], 0.6 , {alpha: 0.8 , scaleX: 1 , scaleY: 1 , delay: 0 , ease: Bounce.easeOut});
    bt [i] .addEventListener (MouseEvent.MOUSE_OVER, overIco)
    bt [i] .addEventListener (MouseEvent.MOUSE_OUT, outIco)
    bt [i] .addEventListener (MouseEvent.CLICK, function [ 0 ] (i));

   
}


// And my fontion

function  affLassociation (Lock: int )
{
if (Lock == 1 )
{
TweenMax.to (the association, 1 , {x: 500 , delay: 0 , ease: Linear.easeOut});
}
else
{
TweenMax.to (the association, 1 , {x: - 1000 , delay: 0 , ease: Linear.easeOut});
}
}












EmoticonEmoticon