dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Shuffle movieclips

  1. #1
    Senior Member
    Join Date
    Feb 2006
    Posts
    124

    Shuffle movieclips

    Hi guys

    I have 9 movie clips on stage that i am shuffling but some of the clip overlap each other how can i prevent this?



    here my code so far
    PHP Code:
    var boxCnt:int 9;
    var 
    boxName:String "output";
    var 
    shuffleArr:Array;

    function 
    setOutput(val:int):void {
        
    shuffleArr = new Array();

        for (var 
    i:uint 1<= boxCnti++) {
            var 
    randKey:int Math.random() * boxCnt;
            if (
    val == 0) {
                
    shuffleArr[i-1] = {id:i,key:i};
                
    //shuffleArr[i-1] = {id:i};
            
    } else {
                
    //shuffleArr[i-1] = {id:i};
                
    shuffleArr[i-1] = {id:i,key:randKey};
            }
            
    shuffleArr.sortOn("key",Array.NUMERIC);
            var 
    tCnt:int 1;
            for(var 
    t:String in shuffleArr) {
                
    this[boxName tCnt].op.text shuffleArr[tCnt-1].id;

                var 
    locationArr:Array = new Array();
                
    locationArr.push({x:226y:73});
                
    locationArr.push({x:278y:73});
                
    locationArr.push({x:330y:73});
                
    locationArr.push({x:226y:121});
                
    locationArr.push({x:278y:121});
                
    locationArr.push({x:330y:121});
                
    locationArr.push({x:226y:167});
                
    locationArr.push({x:278y:167});
                
    locationArr.push({x:330y:167});
                
                var 
    index:Number 0;
                var 
    coordinates:Object;
                
                while (
    locationArr.length 0) {
                    
    coordinates locationArr.splice(Math.random() * locationArr.length1)[0];
                    
    this[boxName tCnt].coordinates.x;
                    
    this[boxName tCnt].coordinates.y;
                    
    index++;
                }
                
    tCnt++;
            }
        }
    }

    this.addEventListener(Event.ENTER_FRAMEclickHandler);

    function 
    clickHandler(ev:Event):void {
        
    setOutput(1);
        
    this.removeEventListener(Event.ENTER_FRAMEclickHandler);
    }
    setOutput(0); 

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Is the problem z-indexing or that you need to adjust spacing in x/y space? Are your clips all the same size? Where is the registration point for each one?

  3. #3
    Senior Member
    Join Date
    Feb 2006
    Posts
    124
    Quote Originally Posted by neznein9 View Post
    Is the problem z-indexing or that you need to adjust spacing in x/y space? Are your clips all the same size? Where is the registration point for each one?
    thanks for the reply!

    All the clips are the same size and the registration point is in the top left hand corner.

    Yes I'm going to space out the movie clips from each other using there height and width.
    PHP Code:
            var widthPiece:int this[boxName i].width;
            var 
    heightPiece:int this[boxName i].height
    and then create an array that will hold there coordinates and then space them out like this.

    PHP Code:
        var locationArr:Array = new Array();

            
    locationArr.push({x:169y:169});
            
    locationArr.push({x:169 widthPuzzlePiece 5y:169});
            
    locationArr.push({x:169 widthPuzzlePiece 10y:169}); 
    But there must be an easier way, any ideas will be appreciated

    here's the updated script but some of the MC are still overlapping each other

    PHP Code:
    var boxCnt:int 9;
    var 
    boxName:String "output";


    function 
    arrangePieces(evt:Event):void {
        for (var 
    i:int 1i<=boxCnti++) {
            var 
    widthPiece:int this[boxName i].width;
            var 
    heightPiece:int this[boxName i].height;

            var 
    locationArr:Array = new Array();
            
    //top row 3 across
            
    locationArr.push({x:169y:169});
            
    locationArr.push({x:169 widthPiece 5y:169});
            
    locationArr.push({x:169 widthPiece 5y:169});
            
    //middle row 3 across
            
    locationArr.push({x:169y:169 heightPiece 5});
            
    locationArr.push({x:169 widthPiece 5y:169 + (heightPiece 5)*2});
            
    locationArr.push({x:169 widthPiece 5y:169 + (heightPiece 5)*2});
            
    //bottom row 3 across
            
    locationArr.push({x:169y:169 + (heightPiece 5)*2});
            
    locationArr.push({x:169 widthPiece 5y:169 + (heightPiece 5)*2});
            
    locationArr.push({x:169 widthPiece 5y:169 + (heightPiece 5)*2});        

            var 
    index:Number 0;
            var 
    coordinates:Object;

            while (
    locationArr.length 0) {
                
    coordinates locationArr.splice(Math.floor(Math.random() * locationArr.length), 1)[0];
                
    this[boxName i].coordinates.x;
                
    this[boxName i].coordinates.y;
                
    index++;
                
    this.removeEventListener(Event.ENTER_FRAMEarrangePieces);
            }
        }
    }
    this.addEventListener(Event.ENTER_FRAMEarrangePieces); 
    Last edited by mathie; 05-07-2009 at 05:03 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center