Help - Search - Members - Calendar
Full Version: Action Script 3 - invisible code
HTMLHelp Forums > Web Authoring > Graphics, Flash and Multimedia
Goo
Hi

I am writing AS3 code and please need help with:
1. When the user picks up the hockey ball and drags it with his mouse into the goal box, the ball must fade away.

i.e. when theBall touches theGoal, theBall must become invisible.

My code:
theBall.addEventListener(MouseEvent.CLICK, trans);
function trans(event:MouseEvent):void
{
theBall.addEventListener(Event.ENTER_FRAME, goal);
}

function goal(event:Event):void
{
if(theBall.x == theGoal.x)
theBall.alpha -= 1;
}


The if(theBall == theGoal) doesn't seem to work. Can someone please help me.


2. Secondly, how can I write some code so that an event must take place when the user clicks the right mouse button and not left?
Frederiek
I'm afraid there are not many people here who know Flash that well to be able to help you. I can't anyway. Sorry.

Try searching for Flash and/or AS 3 tutorials.
roamer
Hi,
Apologies I'm not at my computer at min (using phone) so this is just a quick rep.

Your if statment won't work as your watching for the ball's x to be the exact same as the goal. The x position of an mc refares to a 1 pixel line going from left to right along the screen, which it's anchor point (usualy top left, but depends on ur settings) rest on. U need a hit test such as:

if(ball.hitTestObject(goal)){
trace("GOAL");
}

That should work. I would nesisarily use ENTER_FRAME a timer or setIterval would be better. But I would need to be at a computer to get the code exactly right.

Just remember to remove ur enter frame listener once uv finished with it. I.e once the player scores r they drop the ball. It's just the same as add listener but replace addlustener with removeEventListener

Hope that helps, apologies 4 typos! :s

Lk
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.