-------------------------------------------------------------------------------------------------------------
SIMPLE DRAG ME AS3 RESET BUTTON
//First Make DragMeTarget MovieClip
//Second Draw reply_txt Box
//Third Make DragMe MovieClip
//Four Make Reset Button And Paste Below Code
// DragMe MOVIE CLIP SHOULD BE DRAG UNDER THE MOVIE BECAUSE IT DOESN'T WORK
https://www.youtube.com/watch?v=EgZCUgI39J4
Download Source:
http://bit.ly/1Jmr4iC
--------------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE
---------------------------------------------------------------------------------------------------------------
//First Make DragMeTarget MovieClip
//Second Draw reply_txt Box
//Third Make DragMe MovieClip
//Four Make Reset Button And Paste Below Code
// DragMe MOVIE CLIP SHOULD BE DRAG UNDER THE MOVIE BECAUSE IT DOESN'T WORK
var startX:Number;
var startY:Number;
DragMe.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown)
function MouseDown(e:MouseEvent):void {
startX = e.target.x;
startY = e.target.y;
e.target.startDrag(true);
}
DragMe.addEventListener(MouseEvent.MOUSE_UP,MouseUp)
function MouseUp(e:MouseEvent):void {
e.target.stopDrag();
if (e.target.hitTestObject(getChildByName(e.target.name+"Target"))) {
e.target.x=getChildByName(e.target.name+"Target").x;
e.target.y=getChildByName(e.target.name+"Target").y;
e.target.removeEventListener(MouseEvent.MOUSE_DOWN,MouseDown)
e.target.removeEventListener(MouseEvent.MOUSE_UP,MouseUp)
reply_txt.text = "Good Job!"
}
else {
e.target.x=startX;
e.target.y=startY;
reply_txt.text = "Try Again!"
}
}
Reset.addEventListener(MouseEvent.CLICK,MouseClick);
function MouseClick(event:MouseEvent):void{
DragMe.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown)
DragMe.addEventListener(MouseEvent.MOUSE_UP,MouseUp);
DragMe.x = startX;
DragMe.y = startY;
reply_txt.text = "Play Again!"
}
-----------------------------------------------------------------------------------------------------------------
HOW USE UPPER CODE IN CLASS FORMAT AFTER SWF DECOMPILER MY FILE
GIVE ERROR RELATED
-------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
1- WRITE THIS WORD IN CLASS BOX MainTimeline
-----------------------------------------------------------------------------------------------------------------------
package{
import flash.display.*;
import flash.events.*;
import flash.text.*;
dynamic public class MainTimeline extends MovieClip {
public var Reset:MovieClip;
public var DragMeTarget:MovieClip;
public var reply_txt:TextField;
public var DragMe:MovieClip;
public var startX:Number;
public var startY:Number;
public function MainTimeline(){
addFrameScript(0, this.frame1);
return;
}
public function MouseDown(event:MouseEvent) : void {
this.startX = event.target.x;
this.startY = event.target.y;
event.target.startDrag(true);
return;
}
public function MouseUp(event:MouseEvent) : void{
event.target.stopDrag();
if (event.target.hitTestObject(getChildByName(event.target.name + "Target"))){
event.target.x = getChildByName(event.target.name + "Target").x;
event.target.y = getChildByName(event.target.name + "Target").y;
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, this.MouseDown);
event.target.removeEventListener(MouseEvent.MOUSE_UP, this.MouseUp);
this.reply_txt.text = "Good Job!";
}
else{
event.target.x = this.startX;
event.target.y = this.startY;
this.reply_txt.text = "Try Again!";
}
}
public function MouseClick(event:MouseEvent) : void{
this.DragMe.addEventListener(MouseEvent.MOUSE_DOWN, this.MouseDown);
this.DragMe.addEventListener(MouseEvent.MOUSE_UP, this.MouseUp);
this.DragMe.x = this.startX;
this.DragMe.y = this.startY;
this.reply_txt.text = "Play Again!";
return;
}
function frame1(){
this.DragMe.addEventListener(MouseEvent.MOUSE_DOWN, this.MouseDown);
this.DragMe.addEventListener(MouseEvent.MOUSE_UP, this.MouseUp);
this.Reset.addEventListener(MouseEvent.CLICK, this.MouseClick);
return;
}
}
}
--------------------------------------------------------------------------------------------------------------
2) USE UPPER CODE IN THE WAY
TEXT BOX USE UNDER MOVIE CLIP IN AS
Dowload Source File:
https://www.youtube.com/watch?v=V_FxgUkreek
---------------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE
---------------------------------------------------------------------------------------------------------------
//First Make GreenBoxMc And Double Click This Movie And Draw reply_txt Box
//Second Make DragMeTarget MovieClip
//Third Make DragMe MovieClip
//Four Make Reset Button And Paste Below Code
// DragMe MOVIE CLIP SHOULD BE DRAG UNDER THE MOVIE BECAUSE IT DOESN'T WORK
var startX:Number;
var startY:Number;
DragMe.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown)
function MouseDown(e:MouseEvent):void {
startX = e.target.x;
startY = e.target.y;
e.target.startDrag(true);
}
DragMe.addEventListener(MouseEvent.MOUSE_UP,MouseUp)
function MouseUp(e:MouseEvent):void {
e.target.stopDrag();
if (e.target.hitTestObject(getChildByName(e.target.name+"Target"))) {
e.target.x=getChildByName(e.target.name+"Target").x;
e.target.y=getChildByName(e.target.name+"Target").y;
e.target.removeEventListener(MouseEvent.MOUSE_DOWN,MouseDown)
e.target.removeEventListener(MouseEvent.MOUSE_UP,MouseUp)
GreenBoxMc.reply_txt.text = "Good Job!"
}
else {
e.target.x=startX;
e.target.y=startY;
GreenBoxMc.reply_txt.text = "Try Again!"
}
}
EmoticonEmoticon