|
-
Actually here's the complete explanation
This is what it looks like

The black ball can be dragged. I want the ball to be able to travel between the hole. But if it touches the black coloured area, it has to go and play "main"
And this is my code
Actionscript Code:
stop();
var lvl1:MovieClip = new Linelvl1(); lvl1.x = 400; lvl1.y = 240; addChild(lvl1); lvl1.alpha = 0;
var ball:MovieClip = new Ball(); ball.x = 80; ball.y = 380; addChild(ball);
addEventListener(Event.ENTER_FRAME, onStart);
function onStart(evt:Event) { var myTimer:Timer = new Timer(1000, 1); myTimer.addEventListener(TimerEvent.TIMER, timerListener); function timerListener (evt:TimerEvent) { if (lvl1.alpha < .75) { lvl1.alpha += .05; } } myTimer.start(); ball.addEventListener(MouseEvent.MOUSE_DOWN, onDrag); ball.addEventListener(MouseEvent.MOUSE_UP, onStopDrag); function onDrag(evt:MouseEvent) { ball.startDrag(true); } function onStopDrag(evt:MouseEvent) { ball.stopDrag(); } if (lvl1.alpha == .75) { if (lvl1.hitTestObject(ball)) { removeEventListener(Event.ENTER_FRAME, onStart); removeChild(lvl1); removeChild(ball); gotoAndStop("main"); ball.removeEventListener(MouseEvent.MOUSE_DOWN, onDrag); ball.removeEventListener(MouseEvent.MOUSE_UP, onStopDrag); } } }
-
Dignitary
Clips are always squares for hitTest objects so you kinda have to make 3 separate walls unless you wanna use some of the fancier hitTest class files out there.
I'm not sure of the need for your objects to be class files in the library either. If you can, you should consider just drawing the object and convert to symbols. It would make the code rather simple:
PHP Code:
import flash.events.MouseEvent;
import flash.events.Event;
ball.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
ball.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
ball.addEventListener(Event.ENTER_FRAME, hitWalls);
function hitWalls(e:Event):void{
if(e.currentTarget.hitTestObject(wall1)||e.currentTarget.hitTestObject(wall2)||e.currentTarget.hitTestObject(wall3)){
e.currentTarget.stopDrag();
e.currentTarget.x=28;
e.currentTarget.y = 303;
}
}
function stopDragging(m:MouseEvent):void{
m.currentTarget.stopDrag();
}
function startDragging(m:MouseEvent):void{
m.currentTarget.startDrag();
}
-
 Originally Posted by rynoe
Clips are always squares for hitTest objects so you kinda have to make 3 separate walls unless you wanna use some of the fancier hitTest class files out there.
I'm not sure of the need for your objects to be class files in the library either. If you can, you should consider just drawing the object and convert to symbols. It would make the code rather simple:
PHP Code:
import flash.events.MouseEvent;
import flash.events.Event;
ball.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
ball.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
ball.addEventListener(Event.ENTER_FRAME, hitWalls);
function hitWalls(e:Event):void{
if(e.currentTarget.hitTestObject(wall1)||e.currentTarget.hitTestObject(wall2)||e.currentTarget.hitTestObject(wall3)){
e.currentTarget.stopDrag();
e.currentTarget.x=28;
e.currentTarget.y = 303;
}
}
function stopDragging(m:MouseEvent):void{
m.currentTarget.stopDrag();
}
function startDragging(m:MouseEvent):void{
m.currentTarget.startDrag();
}
Thank you for your help
I'm really trying to understand what you're saying but I can't
1. My wall is only one as you see it in the picture. How do you want me to create 3 walls
2. what are the x = 28 and y = 303 for??
\
thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|