Copy link to clipboard
Copied
I have made a simple "maze game" which works like this:.
If player accidentally touches (rollover) my walls (button), player is sent to frame 10. If they reach the end goal(sleepingBaby) then they are sent to frame 20. From either frame 10 (win) or frame 20 (lose), they can hit a replay button whch sends them back to frame 1. game is working fine except for one small problem.
In frame 1, I successfully remove the mouse and add a Movie Clip to the Mouse/Cursor. I remove the MC when they go to frame 10 OR frame 20 and then when they replay and are sent back to frame 1. The MC again appears as the Cursor. GREAT. Now here's my problem. When they are sent back to frame 1, I want the Cursor to be at an exact position to replay the game. Right now, it ends up wherever they have the cursor pointing and if it is touching my "walls", game over immediately. Here is the code I have on frame 1. It is working BUT I need to add code that makes the cursor ALSO go to a specific position. In this example I am attempting to add an "if'else" staement that says, if playhead is on frame 1, set it's position to 100,100. Else, let the MC follow the cursor. Here is link to video of game in action.
http://screencast.com/t/a3qcTm92Nmzw
Here is my current code:
stop();
lions_btn.addEventListener(MouseEvent.MOUSE_OVER, lose);
function lose(event:MouseEvent):void
{
gotoAndStop(20);
}
babySleep_btn.addEventListener(MouseEvent.MOUSE_OVER, win);
function win(event:MouseEvent):void
{
gotoAndStop(10);
}
stage.addChild(feather4_mc);
feather4_mc.mouseEnabled = false;
feather4_mc.addEventListener(Event.ENTER_FRAME, featherMouse);
function featherMouse(event:Event):void
{
if (feather4_mc.currentFrame = 1)
{
feather4_mc.x = 100;
feather4_mc.y = 100;
}
else
{
feather4_mc.x = stage.mouseX;
feather4_mc.y = stage.mouseY;
}
}
Mouse.hide();
I am sure this can be done BUT My code is NOT sending the cursor to 100,100. Can anyone see my error and help me? Thank You Gene
Copy link to clipboard
Copied
Equal sign should be double:
if (feather4_mc.currentFrame == 1)
{
feather4_mc.x = 100;
feather4_mc.y = 100;
}
Copy link to clipboard
Copied
TY so much Relax. That helped. My cursor now goes to where I would like it to go when player hits "replay". BUT there is a conflict since the cursor wants to go back to frame 1 and ALSO follow the mouse. Here is a link that shows what is happening now:
http://screencast.com/t/mhVyfLJC
Here is the present code:
stop();
lions_btn.addEventListener(MouseEvent.MOUSE_OVER, lose);
function lose(event:MouseEvent):void
{
gotoAndStop(20);
}
babySleep_btn.addEventListener(MouseEvent.MOUSE_OVER, win);
function win(event:MouseEvent):void
{
gotoAndStop(10);
}
stage.addChild(feather4_mc);
feather4_mc.mouseEnabled = false;
feather4_mc.addEventListener(Event.ENTER_FRAME, featherMouse);
function featherMouse(event:Event):void
{
if (feather4_mc.currentFrame == 1)
{
feather4_mc.x = 50;
feather4_mc.y = 370;
}
else
{
feather4_mc.x = stage.mouseX;
feather4_mc.y = stage.mouseY;
}
}
Mouse.hide();
I have a stop(); on frame 1. THAT may be causing the problem? Do you know how I should modify this script to allow the cursor to position itself at "start here" but ALSO follow the mouse? TY Gene
Copy link to clipboard
Copied
feather4_mc have how many frames? Why it relevantly updating the frame thats why the cursor placed once in start here even you moving the cursor. Whatz ur target?
Copy link to clipboard
Copied
Relax, Not sure I understand your your question about how many frames
feather4_mc has. It is a Movie Clip that follows the mouse during the
game. It is a gif animation. The gif has 4 frames. My target ? Do
you mean the babySleeping_mc at the end of the maze ? How could I change
the code to position the feather4_mc at "start here" ONLY at the start of
the game in frame 1. Thank You for helping me solve this problem. Gene
Copy link to clipboard
Copied
Set this code outside of the enterframe:
feather4_mc.x = 50;
feather4_mc.y = 370;
So when you start the game the position will be there.
The problem because of your enterFrame event, it triggers immediately when you start the game:
Solution is trigger the event after sometime or have the start here as a button and when you click raise the following event:
feather4_mc.addEventListener(Event.ENTER_FRAME, featherMouse);
and there is no need of the below code in the featherMouse function: remove the following code
if (feather4_mc.currentFrame == 1)
{
feather4_mc.x = 50;
feather4_mc.y = 370;
}
Copy link to clipboard
Copied
Ok Relax. I took your second idea of making the "start here" a button and
sending it to frame 2. I had to place all my working game code on frame 2
and I placed the following code on frame 1 with along with a text graphic
for and introductory Welcome and Instructions:
import flash.events.MouseEvent;
stop();
feather_mc.x = 50;
feather_mc.y = 370;
start_btn.addEventListener (MouseEvent.CLICK, startHere)
function startHere (Evt:MouseEvent) :void{
gotoAndPlay (2);
}
Then the rest of the code for the game is on frame 2. It seems to work.
Thank you very much. I now want to email the swf to my friends to test it
for me. Any suggestions about 2 things:
1. How to I change the swf icon to a "Lion Icon" ?
2. Do I just attach the swf as an email attachment or any other Ideas for
distribution.
Thanks again, Gene
Copy link to clipboard
Copied
Publish the file as an exe and make a zip file, so that no one not extract from decompiler. Somewhat a protection. Please mark the thread as answered.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now