-
How do you trace inside a movieclip?
Hi, so I created my movieclip and gave it this code:
Code:
onClipEvent (load) {
if (day < 15) {
this.gotoAndStop(1);
} else if (day >= 15) {
this.gotoAndStop(2);
}
}
Inside the movieclip I have 2 frames. They both look completely different. In my game if day is less than 15, I want my movieclip to stay on frame 1, if day is greater than or equal to 15 I would like my movieclip to go to frame 2. The problem I'm having with my code is that my movieclip stays on frame 2 regardless of what day it is. Does anyone know how to fix this?
-
.
Hi,
You might find that
PHP Code:
onClipEvent (load)
only achieves the command on loading, so maybe look into using
PHP Code:
onClipEvent (enterframe)
you would trace inside a movieclip the same way you would out of one
-
Personally I wouldnt do it as an onClipEvent.
the var day Im guessing is on the main timeline
I would do:
Code:
MC.onEnterFrame = function (){
if (day < 15) {
MC.gotoAndStop(1);
} else if (day >= 15) {
MC.gotoAndStop(2);
}
}
This way the statement is checked at the frame rate if you dont need it checked as frequently
Ie, the time of day only progresses from a proceeding function you can set it as its one function to only check when you add 1 to day.
Code:
function dayCheck(){
if (day < 15) {
MC.gotoAndStop(1);
} else if (day >= 15) {
MC.gotoAndStop(2);
}
}
//Then add the the function to the process
dayCheck();
//if doing this method you will need to place it at the top for your actions frame to check when the frame loads for the first time.
Hope some of this helps you out
Trust my code, and not my english.
-
.
Hi,
Expanding on the last comment, try this on your first frame on the timeline.
PHP Code:
stop();
function CheckDay()
{
GetDay = new Date();
TheDay = GetDay.getDate();
if (TheDay < 15)
{
gotoAndStop(1);
}
else
{
gotoAndStop(2);
}
trace(TheDay);
}
CheckDay();
then you can always add the at the completion of a game too. just in case somebody happens to be playing it around midnight!!!
to trace inside a movieclip use something like
PHP Code:
trace(myMovieClipName.MyObject._x);
for example
Last edited by fruitbeard; 01-24-2013 at 09:41 AM.
-
Looks good depends if he is referring to real day of the month or just from a var of his own.
One warning RaynbowzRule.
If you are basing off the real day in the month, the functions run off your system date and time, so a player could change there clock to change the time in the game.
Best of luck though
Trust my code, and not my english.
-
I'm sorry, I do not understand the code. Could you maybe explain? I am not referring to real time, my game has a var called day that goes up to 30 days.
-
.
Hi,
PHP Code:
// function to check day var
function CheckDay()
{
// if day var is less than 15, movie clip goto frame 1.
if (day < 15)
{
MC.gotoAndStop(1);
}
// else if day var is greater or equal to 15, movie clip goto frame 2.
else
{
MC.gotoAndStop(2);
}
// displays actual day var in output panel
trace(day);
}
// call the check day var function
CheckDay();
// the above command can be placed anywhere, when a game is complete, before a game is started etc etc
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
|