2012-05-07 11 views
0

現在、私は現在、純粋なアクションスクリプトプロジェクトのドラッグドロップアプリケーションを開発中です。今私が持っている問題は、私はそれの周りにいくつかの透明な背景といくつかのPNGビットマップがあります。ビットマップがお互いに衝突する可能性があります。ユーザーは、これらのビットマップのいずれかをドラッグすることができます。ユーザーが透明領域をクリックすると、ユーザーはドラッグできなくなります。逆に、透明なビットマップを無視して最上位ビットマップをドラッグできるはずです。As-3透明度付きビットマップのドラッグ

誰でも助けてください。

ありがとうございます。

答えて

2

可能です。 ASの可能性についての詳細なドキュメントを読む必要があります。ここ

だけで、迅速かつ汚れている概念の証明:

package 
{ 
import flash.display.Bitmap; 
import flash.display.BitmapData; 
import flash.display.DisplayObject; 
import flash.display.Sprite; 
import flash.events.MouseEvent; 
import flash.geom.Point; 

/** 
* ... 
* @author Jevgenij Dmitrijev (http://www.ifmi.lt) 
* 
*/ 
public class DragTransparentBitmaps extends Sprite 
{ 
    private var _dragMC:Sprite; 

    public function DragTransparentBitmaps() 
    { 
     var sp:Sprite; 
     var bmp:Bitmap; 

     for (var i:uint; i < 10; ++i) 
     { 
      sp = new Sprite(); 
      sp.name = 'item_' + i.toString(); 
      bmp = new Bitmap(new Close()); // add your bitmapData 
      sp.addChild(bmp); 
      sp.x = 20*i; 
      sp.y = 20*i; 
      addChild(sp); 
     } 

     stage.addEventListener (MouseEvent.MOUSE_DOWN, handleMouseDown) 
    } 

    function handleMouseDown(e:MouseEvent):void 
    { 
     /* 

     // OPTIONAL: 

     // if you need the mouse to be in a specific region:    
     if (mouseX > 400 || mouseY > 400) 
     { 
      return; 
     } 

     // or you can just check if mouse is on your needed mc: 
     if (!someSprite.hitTestPoint(mouseX, mouseY)) 
      return; 
     */ 


     // cheking how much objects are under the mouse 
     var objectsUnderMouse:Array = getObjectsUnderPoint (new Point (mouseX, mouseY)); 

     var length_i:uint = objectsUnderMouse.length; 

     if (length_i > 0) 
     { 
      // if only one then no checking needed just parsing it to the drag function. 
      if (length_i == 1) 
      { 
       drag(objectsUnderMouse[0].parent); 
       return; 
      } 
     } 
     else 
      return; // if nothing under the mouse just end the function 

     var sp:Sprite; 
     var bmpData:BitmapData; 

     for (var i:uint; i < length_i; i++) 
     { 
      // taking a sprite where bitmap is positioned 
      sp = objectsUnderMouse[i].parent as Sprite; 

      // taking the bitmap data 
      bmpData = objectsUnderMouse[i].bitmapData; 

      // taking the pixel information (see the docu about it) 
      // if the value is > 0 it means that the bitmap is not transparent and we can move it 
      if (bmpData.getPixel32(sp.mouseX, sp.mouseY) > 0) 
      { 
       drag (objectsUnderMouse[i].parent); 
       return; 
      } 
     } 
    } 

    // just drag functions 
    private function drag(value:DisplayObject):void 
    { 
     _dragMC = value as Sprite; 
     _dragMC.startDrag(); 

     stage.addEventListener (MouseEvent.MOUSE_UP, handleMouseUp); 
    } 

    private function handleMouseUp(e:MouseEvent):void 
    { 
     stage.removeEventListener (MouseEvent.MOUSE_UP, handleMouseUp); 
     _dragMC.stopDrag(); 
    } 
} 
} 

は、それが役に立ったなら、私に知らせてください。

+0

ありがとうございました.. – premeclat

+0

回答をマークしてください:) –

関連する問題