0 Replies Latest reply on Jul 17, 2009 4:10 AM by Sreelash

    Bitmap Issue

    Sreelash Level 1

      Hi, I am trying to make a transition. i have attached a document with this thread, which contains the image of transition i trying to do.

      For that I am using a Bitmap class. Using the following code i am loading image as Bitmap:

       

                     import flash.display.*
                     import flash.geom.*

       

                     var bitmapArr:Array = new Array();
                     var w = Stage.width;
                     var h = Stage.height;

       

                     container = this.createEmptyMovieClip("container", 1)
                     holder = container.createEmptyMovieClip("holder", 1)

       

                     var bitmap:BitmapData = new BitmapData(301,200,true);

       

                     var Listener:Object = new Object();
                     Listener.tmc = holder;
                     Listener.onLoadInit = function(ImageMc:MovieClip) {
                         ImgLoader.removeListener(Listener);   
                         //var bitmap:BitmapData = new BitmapData(ImageMc._width, ImageMc._height, true);
         
                         this.tmc.attachBitmap(bitmap,2,"auto",true);
                         bitmapArr.push(bitmap)
                         bitmap.draw(ImageMc);                       
                     };      

       

      After loading the image I am calling a function named Disolve, which is shown below:

       

                function Disolve(){
                         var pieces:Array = new Array() //array to store references to each piece
                         var area:Number = 10 //default, should be divisible by image heigth/width
                         var col:Number = w/area
                         var fil:Number = h/area
                         var p:Point = new Point(0, 0)
                         var counter:Number = 150


                         // Copy image and show in MovieClips
                         for(var c=0; c<col; c++){
                             for(var f=0; f<fil; f++){


                                 //Create a bitmapData for each slot
                 
                                 this[c+"_"+f] = new BitmapData(area, area, false, 0xFFFF00)

                                 //Create a container and store in an array
                                 t = container.createEmptyMovieClip("MC"+c+"_"+f, counter++)
                                 pieces.push(t)

                               //store a random velocity for transition
                               t.velx = int(Math.random()*10)+5;
                               t.vely = int(Math.random()*10)+5;

                               //random direction
                              if(int(Math.random()*2)>0) t.velx = -t.velx
                              if(int(Math.random()*2)>0) t.vely = -t.vely

                              //copy bitmap to MovieClip
                              t.attachBitmap(this[c+"_"+f], 1)


                              //calculate area to copy
                              var px:Number = c*area
                              var py:Number = f*area
                              t._x = container.holder._x + px
                              t._y = container.holder._y + py
                              var zone:Rectangle = new Rectangle(px, py, area, area)


                              //copy pixels on this area
                              this[c+"_"+f].copyPixels(bitmapArr, zone, p)
                           }
                    }
                    for(var i=0;i<pieces.length;i++){
                        trace(pieces[i]);
                    }
                
                    for(var i in pieces) pieces[i].linearMove(600) 
               }

       

       

                MovieClip.prototype.linearMove = function(dist:Number) {
                    this.walked = 0;
                    this.onEnterFrame = function() {
                        this._x += this.velx;
                        this._y += this.vely;
                        this.walked += int(this.vel);
                        if (this.walked>dist) {
                           delete this.onEnterFrame;
                            this.removeMovieClip();
                        }
                    };
                };

       

      The disolve function works correctly except one thing. I hope so. The image is divided in to number of pieces for the transition. Then each pieces moves randomly in to different position and finally all pieces moves to outside of stage. But I think the portion of image is not copying in to each pieces. The screenshot of the transition that i had is copied in to the attached document.