可能です。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();
}
}
}
役に立ったかどうか教えてください。