Hello, i need help in converting this code to as3.. especially this line i want to understand what it means:
circle_mc.onRelease = circle_mc.onReleaseOutside=function () What it mean by the =? How to create function inside a function in As3?
I tried converting it to as3 but have some bug.
THE AS2 CODE:
CODE
circle_mc.onPress = function() {
startDrag(this);
};
circle_mc.onRelease = circle_mc.onReleaseOutside=function () {
stopDrag();
if (this._droptarget == "/targetCircle") {
this.onTarget = true;
_root.targetCircle.gotoAndStop(2);
} else {
this.onTarget = false;
_root.targetCircle.gotoAndStop(1);
}
};
//the variables below will store the clips starting position
circle_mc.myHomeX=circle_mc._x;
circle_mc.myHomeY=circle_mc._y;
//the variables below will store the clips end position
circle_mc.myFinalX = 443;
circle_mc.myFinalY = 294;
circle_mc.onMouseDown = function() {
//this variable tells us if the mouse is up or down
mousePressed = true;
};
circle_mc.onMouseUp = function() {
mousePressed = false;
};
circle_mc.onEnterFrame = function() {
//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)
// then move the MC back to its original starting point (with a smooth motion)"
if (mousePressed == false && this.onTarget == false) {
this._x -= (this._x-this.myHomeX)/5;
this._y -= (this._y-this.myHomeY)/5;
//if the circle is dropped on any part of the target it slides to the center of the target
} else if (mousePressed == false && this.onTarget == true) {
this._x -= (this._x-this.myFinalX)/5;
this._y -= (this._y-this.myFinalY)/5;
}
};
AS3 CODE(I tried to convert but some bug)
[code]var onTarget:Boolean;
var mousePressed:Boolean;
var myHomeX:Number;
var myHomeY:Number;
var myFinalX:Number;
var myFinalY:Number;
circle_mc.addEventListener("mouseDown", mouseDownHandler);
circle_mc.addEventListener("mouseDown", mouseDownHandler2);
circle_mc.addEventListener("mouseUp", mouseUpHandler);
circle_mc.addEventListener("mouseUp", mouseUpHandler2);
circle_mc.addEventListener("enterFrame", enterFrameHandler);
function mouseDownHandler(event:Event):void
{
startDrag();
}
function mouseUpHandler(event:Event):void
{
stopDrag();
if (this.dropTarget == "targetCircle")
{
this.onTarget = true;
_root.targetCircle.gotoAndStop(2);
}
else
{
this.onTarget = false;
_root.targetCircle.gotoAndStop(1);
}
}
myHomeX = circle_mc.x;
myHomeY = circle_mc.y;
myFinalX = 443;
myFinalY = 294;
function mouseDownHandler2(event:Event):void
{
mousePressed = true;
}
function mouseUpHandler2(event:Event):void
{
mousePressed = false;
}
function enterFrameHandler(event:Event):void
{
if(mousePressed == false && this.onTarget == false)
{
this.x -= (this.x-this.myHomeX)/5;
this.y -= (this.y-this.myHomeY)/5;
}
else if(mousePressed == false && this.onTarget == true)
{
this.x -= (this.x-this.myFinalX)/5;
this.y -= (this.y-this.myFinalY)/5;
}
}[\code]
This post has been edited by Jonson: 27 Jul, 2008 - 08:36 PM