English 中文(简体)
加入AS3号《Array》
原标题:Adding Event Listeners to an Array that Execute Drag and Drop Functions in AS3

这是我第一次真正的方案拟订努力,这是我从成功中几乎没有项目回头来的最后一件事。

我以这一守则为目标,是增加一系列电影剪辑的听众,这些剪辑将拖拉,并放下。

该守则是:

var itemBank:Array = new Array(d1_anim.drawer1.test01.movieClip_1, d1_anim.drawer1.test01.movieClip_2);

for(var i:int = 0; i < itemBank.length; i++) {
    itemBank[i].buttonMode = true;
    itemBank[i].addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    itemBank[i].addEventListener(MouseEvent.MOUSE_UP, dropOff);
    trace("pickUp added to " + itemBank[i]);
}

function pickUp(event:MouseEvent):void
{
    event.target.startDrag(true);
    trace("Draging " + event.target);
}

如今,文化、青年和体育部并不拖延,而微小声明则指出:

页: 1 添加到[影印片]

EDIT: Here is my fla, I give up. I don t know why it wont work. Please help. [Download it here](Edit: removed download link)

最佳回答

Your current code has been tested and works fine. The error must be somewhere else.

如果能下载<<><><>><><>>><>>>>>>>>file/Xlh >p/Drag_rop_Demo. > rel>>>>>>>>>>>> Drag & (Sames ,这只是“the ́s”)。


http://www.un.org。 在这方面,我对你的法典作了修改,使之发挥作用。 阅读这些评论是为了更好地了解。 我还改变了<代码>d1_anim.drawer1.test01.hair1的登记点。 电影不单单单向上,而是需要这样做才能奏效。

import flash.display.MovieClip;
import com.reintroducing.ui.SliderUI; // Always have imports at top. It s a good practice.

var itemBank:Array = new Array(d1_anim.drawer1.test01.hair1);

for(var i:int = 0; i < itemBank.length; i++) {
    itemBank[i].buttonMode = true;
    itemBank[i].mouseChildren = false;// Added this line. For explanation go to: http://ryanbosinger.com/blog/2008/actionscript-3-eventtarget-returns-children-of-movieclip/
    itemBank[i].addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    itemBank[i].addEventListener(MouseEvent.MOUSE_UP, dropOff);
    trace("pickUp added to " + itemBank[i]);
}

function pickUp(e:MouseEvent):void
{
    e.currentTarget.startDrag(true);
    trace("Draging " + e.currentTarget);
}
function dropOff(e:MouseEvent):void
{
    // --- Change  this  to  e.currentTarget  --- \
    e.currentTarget.stopDrag();
    e.currentTarget.x = mouseX;
    e.currentTarget.y = mouseY;
    e.currentTarget.width = 200;
    // --- Putting the target in a temporary variable made an error dissapear. --- \
    // --- I don t really know why and i don t really care either --- \
    var tempMC = e.currentTarget;
    this.stage.addChild(tempMC);
    d1_anim.visible = false;
}

And here is a link to the working .fla

问题回答

暂无回答




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

Red5 Security Tutorial

I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

visible property of DisplayObject

For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...