Actionscript 3 如何从精灵as3中选择一个对象
当精灵上有多个对象时,如何从中选择一个对象(通过文件加载的图片)? 我想拖动一个鼠标点击的Actionscript 3 如何从精灵as3中选择一个对象,actionscript-3,Actionscript 3,当精灵上有多个对象时,如何从中选择一个对象(通过文件加载的图片)? 我想拖动一个鼠标点击的 private var spstage1:Sprite = new Sprite(); private var vecpic1:Vector.<String> = new Vector.<String>(); private var iconpic1:iconpic=new iconpic(); spstage1.graphics.beginFill(0xcccccc); sps
private var spstage1:Sprite = new Sprite();
private var vecpic1:Vector.<String> = new Vector.<String>();
private var iconpic1:iconpic=new iconpic();
spstage1.graphics.beginFill(0xcccccc);
spstage1.graphics.drawRect(250,100,450,668);
stage.addChild(spstage1);
spstage1.addChild(iconpic1);
iconpic1.addEventListener(MouseEvent.CLICK, picclicked);
function picclicked(event:MouseEvent):void {
var txtFilter:FileFilter = new FileFilter("picture", "*.jpg;*.png");
//root.browseForOpen("Open", [txtFilter]);
file = new File();
currentload="pic";
file.addEventListener(Event.SELECT, dirSelected);
file.browseForOpen("Select a picture",[txtFilter]);
//
/*file.browse();
file.addEventListener(Event.SELECT,onselect);*/
}
protected function dirSelected(e:Event):void {
var re1:URLRequest=new URLRequest(file.nativePath);
loader=new Loader();
loader.load(re1);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompletepic);
}
function loadCompletepic(event:Event):void{
var pic:BitmapData=new BitmapData(loader.width,loader.height,false);
pic.draw(loader);
bitmap=new Bitmap(pic);
spstage1.addChild(bitmap);
bitmap.x=ix;
bitmap.y=iy;
vecpic1.push(bitmap.name);
}
private-var-spstage1:Sprite=new-Sprite();
私有变量vecpic1:Vector.=新向量();
私有变量iconpic1:iconpic=新iconpic();
spstage1.graphics.beginll(0xCCCC);
spstage1.graphics.drawRect(250100450668);
stage.addChild(spstage1);
spstage1.addChild(iconpic1);
iconpic1.addEventListener(MouseEvent.CLICK,picclicked);
函数picclicked(事件:MouseEvent):void{
var txtFilter:FileFilter=newfilefilter(“图片”,“*.jpg;*.png”);
//root.browseForOpen(“Open”,[txtFilter]);
file=新文件();
currentload=“pic”;
file.addEventListener(Event.SELECT,dirSelected);
browseForOpen(“选择图片”[txtFilter]);
//
/*file.browse();
file.addEventListener(Event.SELECT,onselect)*/
}
已选择受保护的函数(e:事件):void{
var re1:URLRequest=新的URLRequest(file.nativePath);
加载器=新加载器();
装载机。装载机(re1);
loader.contentLoaderInfo.addEventListener(事件.COMPLETE,loadCompletepic);
}
函数loadCompletepic(事件:事件):void{
var pic:BitmapData=新的BitmapData(loader.width,loader.height,false);
图.牵引(装载机);
位图=新位图(pic);
spstage1.addChild(位图);
位图x=ix;
位图y=iy;
vecpic1.push(bitmap.name);
}
将鼠标向下添加到spstage1
事件侦听器
在侦听器处理程序中,选中:
function clickHandler(evt:MouseEvent):void {
if (evt.target is Bitmap) {
// here you decide what you have clicked on.
(evt.target as DisplayObject).startDrag(); // do the stuff for dragging etc.
}
}
此处evt.target将是单击的对象。
你所要做的就是确定它是否是正确的对象。在本例中,它只是被检查为位图类型。如果容器中有其他不需要单击的位图,请使用其他方法,例如将加载的对象存储在某个位置,然后将目标与所有存储的对象进行比较。或者检查您似乎已经拥有的bitmap.name
,等等