Tuesday, 9 February 2016

CHARACTER MOVEMENT WITH MOUSE CLICK AS3 AS2



-----------------------------------------------------------------------------------------------------------------------
YOU CAN MAKE QUIZ  GAME THIS EFFECT WITH HIT TEST CODE
http://flashcollege.blogspot.co.uk/2016/01/inside-action-script-movie-clip-hit.html
CODE:1
1) MAKE MOVIE CLIP IN AS3
2) GIVE INSTANCE NAME=  mc1
http://www.allaboutcoding.com/tutorials/flash/follow_mouse.asp
------------------------------------------------------------------------------------------------------------------------

mc1.addEventListener(Event.ENTER_FRAME, MoveBall);
function MoveBall(evt:Event):void {
var xMouse = root.stage.mouseX;
var yMouse = root.stage.mouseY;
if(Math.abs(xMouse - mc1.x) < 1) {
//if mouse is within 1px move to mouse position
mc1.x = xMouse;
mc1.y = yMouse;
}
else {
//move ball 1/6 of the way to mouse each frame
mc1.x -= (mc1.x-xMouse) / 6;
mc1.y -= (mc1.y-yMouse) / 6;
}}

-----------------------------------------------------------------------------------------------------------------
CODE :2
1) MAKE MOVIE CLIP IN AS3
2) GIVE INSTANCE NAME=  mc1
-----------------------------------------------------------------------------------------------------------------

//https://forums.adobe.com/thread/611048?tstart=0
stage.addEventListener(MouseEvent.CLICK, myClickReaction);
var v:Number = 5;
var clickPoint:Point = new Point();
function myClickReaction (e:MouseEvent):void {
clickPoint.x = mouseX;
clickPoint.y = mouseY;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame(event:Event):void {
var xDistance:Number = clickPoint.x - mc1.x;
var yDistance:Number = clickPoint.y - mc1.y;
var angle:Number = Math.atan2(yDistance, xDistance);
mc1.x += v * Math.cos(angle);
mc1.y += v * Math.sin(angle);
}

------------------------------------------------------------------------------------------------------------
CODE :3
1) MAKE MOVIE CLIP IN AS2
2) INSTANCE NAME = btn1
3) PASTE BELOW CODE INSIDE MOVIE CLIP IN ACTION SCRIPT PANEL

Making Object Move To Mouse
https://www.youtube.com/watch?v=8mp5dMoCXg8
https://multimediawiz.wordpress.com/tutorials/actionscript-2-tutorials/making-object-move-to-mouse/
------------------------------------------------------------------------------------------------------------

onClipEvent(load){
_x = 0;
_y = 0;
speed = 5;
}
onClipEvent(mouseDown){
endX = _root._xmouse;
endY = _root._ymouse;
}
onClipEvent(enterFrame){
_x += (endX-_x)/speed;
_y += (endY-_y)/speed;
}
-------------------------------------------------------------------------------------------------------
AFTER THIS CODE I MAKE SECOND MOVIE 
GIVE INSTANCE NAME = btn2
PASTE CODE IN TIME LINE FRAME
-------------------------------------------------------------------------------------------------------
this.onEnterFrame=function(){
if(btn1.hitTest(btn2)){
btn1._visible=false;
btn2._visible=false;
}}

------------------------------------------------------------------------------------------------------------
NOW FIND CODE:
 [AS2] drag and drop; return to original pos.
https://www.kirupa.com/forum/showthread.php?151162-AS-drag-and-drop-return-to-original-pos
https://www.youtube.com/watch?v=HmQWMAJjK68
https://www.youtube.com/watch?v=mvBFzMD_hEg
-------------------------------------------------------------------------------------------------------------
var startPosition:Point;

mc_d4.addEventListener(MouseEvent.MOUSE_DOWN, dragD4);
stage.addEventListener(MouseEvent.MOUSE_UP, dragStop4);

function dragD4(e:Event):void {
   mc_d4.startDrag();
   startPosition = new Point( mc_d4.x, mc_d4.y);
}

function dragStop4(e:Event):void {
   mc_d4.stopDrag();
   //set back or tween position

   mc_d4.x = startPosition.x;
   mc_d4.y = startPosition.y;

   startPosition = null;

}
--------------------------------------------------------------------------------------------------------------
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001314.html
----------------------------------------------------------------------------------------------------
square_mc.onPress = function() {
this.startDrag();
};
square_mc.onRelease = function() {
this.stopDrag();
if (this.hitTest(circle_mc)) {
trace("you hit the circle");
}}


EmoticonEmoticon