|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ActionScript 3 - Property CLICK not found, game problem
Hello,
I am getting the error message when I put the mouse over the "badBlob": ReferenceError: Error #1069: Property CLICK not found on flash.events.MouseEvent and there is no default value. at collisionChangeCursor_fla::MainTimeline/followCursor()[collisionChangeCursor_fla.MainTimeline::frame1:12] Any thoughts? My Code is: Code:
var score:Number = 0;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,followCursor);
function followCursor(MouseEvent):void
{
if(blob.hitTestObject(badBlob))
{
blob.addEventListener(MouseEvent.CLICK,addToScore);
function addToScore(MouseEvent):void
{
trace("hit bad blob");
score++;
pointsScore.text = score.toString();
}
}
blob.x = mouseX;
blob.y = mouseY;
}
Thankyou for your time, Ford2008
__________________
http://www.advertiseadspace.com Buy & Sell Advertising space in an online marketplace http://www.onepoundscripts.co.uk One pound scripts and up, for Cubecart 3 Last edited by ford2008 : October 19th, 2009 at 10:13 AM. |
|
#2
|
|||
|
|||
|
Hi, it's bugging out because you're trying to assign the mouse event hundreds of times. That's happening because you're assigning the event inside the MouseMove event which gets called very frequently.
Another problem you'll run into is that the click event will never get called since the cursor will almost always be outside the blob clip since you're giving it the same x & y as the mouse. It's a bit hard to explain but an easier way is just to see for yourself. If you comment out the mouse hiding code you'll see that the registration is lined up so the top left corner of the box is directly under the cursor. Because the update routine is always slower than you can move the mouse it means sometimes it will not be at the same position so when you click the mouse it will not actually hit the blob. Here's a cleaned up version that handles both of those issues: Code:
var score:Number = 0;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, followCursor);
stage.addEventListener(MouseEvent.MOUSE_DOWN, addToScore);
function followCursor(event:MouseEvent):void
{
blob.x = mouseX;
blob.y = mouseY;
}
function addToScore(event:MouseEvent):void
{
if (blob.hitTestObject(badBlob))
{
trace("hit bad blob");
score++;
pointsScore.text = score.toString();
}
}
We move the click code so it's on the stage. This means that whenever they click the mouse, be it over the blob or not, the addToScore function will get called. We put the hitTest check in there. That has the added benefit of meaning that it doesn't get called every time you move the mouse giving you a slight performance boost. I also fixed your function headers: Bad: function followCursor(MouseEvent):void Good: function followCursor(event:MouseEvent):void
__________________
Quis custodiet ipsos custodes?
|
|
#3
|
|||
|
|||
|
Thanks, thats great
![]() |
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > ActionScript 3 - Property CLICK not found, game problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|