1 Reply Latest reply on Jul 16, 2009 5:52 AM by kglad

    loading images as bitmap from externally

    Sreelash Level 1

      Hi, In the following application images are attaching from library as bitmap. But i want to load it externally.Actually what I am trying to do is that i want to divide an image in to several pieces and giving a disolve effect for transition. I got a code in which images are loading from the library as bitmap object. I changed it and loaded externally using bitmap, but i cant divide images in to small pieces. I think its due to the problem of loading as bitmap.i just want to modify the following code to load image externally. can anybody help me.

       

       

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

      //Effects availables
      var effects:Array = new Array({label:"Pixels", data:"pixels"}, {label:"Disolve", data:"cuadritos"}, {label:"Turn out", data:"tiras"},{label:"Turn radial", data:"tiras"})
      myCombo.dataProvider = effects
      //combo listener
      effectListener = {}
      effectListener.ref = this
      effectListener
      .change = function(evt:Object){
          var
      action:String = evt.target.selectedItem.data
          this
      .ref.transition = action //set transition
         
      clearInterval(run) //re-create set Interval
         
      var t = (action=="cuadritos") ? 5000 : 2000 //Disolve needs more time
          //call inmediatly
         
      nextImg(this.ref)
         
      //set Interval
         
      run = setInterval(nextImg, 5000, this.ref)    
      }
      myCombo.addEventListener("change", effectListener)
      //Gallery array, bitmaps on library
      var images:Array = new Array("img1", "img2", "img3", "img4", "img5")
      var
      current:Number = 0 //image counter
      //general holder
      a = BitmapData.loadBitmap(images[current])
      w = a.width
      h
      = a.height
      container
      = this.createEmptyMovieClip("container", 1)
      container.createEmptyMovieClip("holder", 1)
      container.holder.attachBitmap(a, new Matrix())
      container.holder._x = 10
      container
      .holder._y = 25
      //Set mask
      container.setMask(foto)
      //default transition
      transition = "pixels";
      //Begin gallery showcase
      run = setInterval(nextImg, 3000, this)    
      function
      nextImg(where){
         
      where.current = ((where.current+1)>where.images.length-1)?0 : where.current+1
          where
      [where.transition](where.current)

       

       

      Following code is using for disolve effect

       

       

       

       

      //Disolve 
      function cuadritos(nr){
         
      //Bitmap data for next image 
         
      var trans:BitmapData = BitmapData.loadBitmap(images[nr])    
          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, 0xFF0000)
                 
      //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(a, zone, p)
              }
          }
         
      //Load new image
         
      container.holder.attachBitmap(trans, 1)
         
      //Fires transition
         
      for(var i in pieces) pieces[i].linearMove(600)
         
      //copy next image
         
      a.draw(container.holder)
         
      //release memory
         
      trans.dispose()
      }