闪存AS3克隆,拖放放大器;下降 [英] Flash AS3 Clone, Drag & Drop

查看:157
本文介绍了闪存AS3克隆,拖放放大器;下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名教师,并与一些你的帮助下,我成功地创造出非常基本的文字游戏的孩子,他们都能够从字母创建的话。 SWF | FLA

I am a teacher and with the help of some of you, I managed to create very basic word game for kids where they are able to create words from letters. SWF | FLA

我有,但是,已经无法继续拖放字母一旦他们被克隆的原件在舞台的一侧。有没有人能劝我怎么可能能够将此功能添加到现有code?

I have, however, been unable to continue to drag and drop the letters once they have been cloned from their originals on the side of the stage. Is anyone able to advise how I might be able to add this functionality to my existing code?

import flash.display.MovieClip;

for (var i=1; i<27; i++)
{
    this["object" + i].addEventListener(MouseEvent.MOUSE_DOWN, onStart);
    this["object" + i].addEventListener(MouseEvent.MOUSE_UP, onStop);
}    

var sx = 0,sy = 0;

function onStart(e)
{
    sx = e.currentTarget.x;
    sy = e.currentTarget.y;
    e.currentTarget.startDrag();
}

function onStop(e)
{
    if (e.target.dropTarget != null && 
    e.target.dropTarget.parent == dest)
    {
        var objectClass:Class = 
        getDefinitionByName(getQualifiedClassName(e.currentTarget)) as Class;
        var copy:MovieClip = new objectClass();
        this.addChild(copy);
        copy.x = e.currentTarget.x;
        copy.y = e.currentTarget.y;
    }

    e.currentTarget.x = sx;
    e.currentTarget.y = sy;
    e.currentTarget.stopDrag();
}

我也很想有一个'本',孩子们可以将信件,如果他们不希望让他们在舞台上了。任何想法如何,我可以补充,这将是极大的AP preciated。

I would also love to include a 'bin' where kids can drag letters if they do not wish to have them on stage any more. Any ideas for how I could add this would be greatly appreciated.

非常感谢。

推荐答案

如果你想为拖动对象类似的行为(即拖动后,复制创建)

If you want similar behavior for dragged object (i.e after dragging, a copy is created)

添加这些行到你的的onStop(E)像这样,

add these line to your onStop(e) like so,

copy.addEventListener(MouseEvent.MOUSE_DOWN, onStart);
copy.addEventListener(MouseEvent.MOUSE_UP, onStop);

但是,如果你只想要拖动和prevent副本,然后创建另一个函数说 dragCopiedObject()并应用拖拽,而不是复制该逻辑新功能

But if you want only dragging and prevent a copy, then either create another function say dragCopiedObject() and apply the logic of dragging and not copying in that new function

在同一的onStop(五)复制或原始对象之间确定的复制功能和prevent。

identify between copied or original object in the same onStop(e) function and prevent from copying.

如果你没有得到它,然后让​​我知道,我会解释给你听的细节。

If you don't get it then let me know I will explain it to you in detail.

有关下探复制的对象的垃圾桶里,拖着停止后,请与仓物碰撞。更多信息看,

For dropping copied objects inside a bin, after dragging is stopped, check collision with bin object. for more info see,

<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject%28%29"相对=nofollow> copiedObject.hitTestObject(binObject)

有关例如。

if(copiedObject.hitTestObject(binObject)) {

     removeChild(copiedObject);
}

更新:为了确定之间复制的对象使用名称属性,如下:

copy.name =复制;

copy.name = "copy";

我修改了code,

function onStop(e)
{
    if ( e.target.dropTarget != null && 
         e.target.dropTarget.parent == dest && 
         e.currentTarget.name != "copy"         ) //This is newly added
    {
        var objectClass:Class = 
        getDefinitionByName(getQualifiedClassName(e.currentTarget)) as Class;

        var copy:MovieClip = new objectClass();
        copy.name = "copy"; //This is newly added
        this.addChild(copy);
        copy.x = e.currentTarget.x;
        copy.y = e.currentTarget.y;

        e.currentTarget.x = sx;
        e.currentTarget.y = sy;

        copy.addEventListener(MouseEvent.MOUSE_DOWN, onStart);
        copy.addEventListener(MouseEvent.MOUSE_UP, onStop);
    }    

    e.currentTarget.stopDrag();
}

这篇关于闪存AS3克隆,拖放放大器;下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆