Friday 13 February 2015

Swap A MovieClip With Another?



var MovieArray = [MOVIE1,MOVIE2,MOVIE3]
for (i = 0; i < MovieArray.length; i++){
MovieArrayFunction(MovieArray[i]);

function MovieArrayFunction(MovieArray){
MovieArray.onPress = function (){
MovieArray.startDrag();
}
MovieArray.onRelease = function (){
MovieArray.stopDrag();
}}  

--------------------------------------------------------------------------------------------------------------------
https://wilsonas3tutorial.wordpress.com/simple-card-matching-game-tutorial/simple-card-matching-game-tutorial-2/
---------------------------------------------------------------------------------------------------------------------


var fCards:Array = new Array(mc1, mc2, mc3, mc4, mc5, mc6, mc7, mc8, mc9, mc10, mc11, mc12);

for(var i:int = 0;  i < fCards.length;  i++)
{

var randomNum:Number;
var xPos:Number;
var yPos:Number;

randomNum = Math.floor(Math.random()*fCards.length);

xPos = fCards[randomNum].x;
yPos = fCards[randomNum].y;

fCards[randomNum].x = fCards[i].x;
fCards[randomNum].y = fCards[i].y;
fCards[i].x = xPos;
fCards[i].y = yPos;

}

-----------------------------------------------------------------------------------------------------------------------------
http://themeforest.net/forums/thread/as3-array-of-movieclips/23084
----------------------------------------------------------------------------------------------------------------------


doru  SAYS
this should work

var myArray:Array = new Array();
var one:MovieClip = instance1;
var two:MovieClip = instance2;
myArray.push(one);
myArray.push(two);
for(var i:uint = 0; i < myArray.length; i++)
{
      myArray[i].x += 100; //example of accessing the array elements
}


or maybe

var myArray:Array = new Array();
myArray.push(instance1);
myArray.push(instance2);
for(var i:uint = 0; i < myArray.length; i++)
{
      myArray[i].x += 100; //example of accessing the array elements
}










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

http://stackoverflow.com/questions/4509518/as2-array-random-selection

var myArray = quotes.slice(); // make a copy so that the original is not altered //
n = 12;
for (var i:Number = 0; i < n; i++) {
    var randomSelection = Math.floor((Math.random() * myArray.length));
    trace("Selected: " + myArray[randomSelection]);
    myArray.splice(randomSelection, 1);
}


-----------------------------------------------------------------------------------------------------------------------------
http://stackoverflow.com/questions/15392348/switch-movieclip-position-with-one-another-as3
Do you mean something like this:
function swap(mcA:MovieClip, mcB:MovieClip):void
{
    var tempPosition:Point = new Point(mcA.x, mcA.y);
    mcA.x = mcB.x;
    mcA.y = mcB.y;

    mcB.x = tempPosition.x;
    mcB.y = tempPosition.y;
}
swap(mc1, mc4);
This will swap the positions of mc1 and mc4.
var totalItems:int = 24; // total number of items
for(var i:int = 0; i < int(totalItems/2); i++)
{
    var randomItem:String = "mc"+(int(Math.random() * (int(totalItems/2)-1)) + (int(totalItems/2)+1));
    swap(this["mc"+(i+1)], this[randomItem]);
}


EmoticonEmoticon