中,拖放和复制 - 闪存AS3 [英] Drag, Drop and Clone - Flash AS3
问题描述
我是一名老师试图让一个简单的Flash AS3游戏,学生可以拖动从AZ(影片剪辑)的任何信件了舞台上,以创建单词中间。
I am a teacher trying to make a simple Flash AS3 game where students can drag any letter from a-z(movieclips) out to the middle of the stage to create words.
我是一个总的业余和Flash等使用code片段,我已经成功地使用户可以拖放字母开头,但我真的想为用户能够拖放一个字母离开原信影片剪辑到位和克隆一个新的多次是必要的。
I am a total amateur with Flash and so using code snippets, I have been successful in allowing users to drag and drop letters but what I would really like is for users to be able to drag and drop a letter leaving the original letter movieclip in place and clone a new one as many times as is necessary.
有没有人能帮助我,我需要做到这一点的AS3?非常感谢。
Is anyone able to help me with the AS3 I would need to achieve this? Many thanks.
推荐答案
Here is a quick sample. FLA | SWF
code:
import flash.display.MovieClip;
for (var i=1; i<5; 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();
}
希望你可以把它提前和放大器;变成东西给你的孩子非常有用。
Hoping you could take it ahead & turn into something useful for your kids.
这篇关于中,拖放和复制 - 闪存AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!