-
HeLLp! Telltarget??
Hi!
I'm trying to do something very simple.
Get a random number.
That number tell me which movieclip to start the animation on. On a 5 second interval
So it looks like:
Code:
function myinterval()
{
var randomNum:Number = Math.random();
var mcnumber:Number = Math.round(Math.random() * (16 - 1)) + 1;
trace(mcnumber);
if(mcnumber == 0)
{
mcnumber = 5;
}
var test2 = "all.sq"+mcnumber;
test2.gotoAndPlay(2);
// That's where I can't tell the MC to gotoAndPlay2 (ex: mcnumber = 2, so to // tell the all.sq2.gotoAndPlay(2); )
}
Simple? Not for me :P Plus I'd like to call that function on a 5 second interval? Any help would be appreciated. Can't seem to get the AS2 to AS3 transition
-
trace("AKA: Biro Barna");
Maybe something like this:
PHP Code:
// assuming that you have your movie clips on the stage // and all your movie clips have a generic name of // mc1, mc2, mc3, mc4, mc5 and so on, you could use // something like this to achieve your goal
// in the following example, I'll be using only mc1 and mc2 // if you are using more movie clips, just edit the code and // increase the range of random values
import flash.utils.Timer; import flash.events.TimerEvent;
var timer:Timer; var timerDelay:Number = 5000; // set the call delay in milliseconds var randomMc:Number = 0; // instantiate your randomMc variable
init(); // call the init(); function
function init():void { // instantiate your timer object timer = new Timer(timerDelay); timer.start(); // start the timer
// handle the timer, call a function on each trigger timer.addEventListener(TimerEvent.TIMER, onTimer); } // end of init
function onTimer(event:TimerEvent):void { // get a value from 1 to 2 randomMc = Math.floor((Math.random() * 2) + 1); trace(randomMc); // display the randomly choosen number // play a random movie clip this["mc" + randomMc].play(); } // end of onTimer
Good luck.
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
trace("AKA: Biro Barna");
In case you don't want to same movie clip to play more then once, then you'll need to hold all your objects in an array and keep picking a random movie clip from the array, play that random movie clip and at the same time remove it from the array...
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
Greeattt!
Great THX alot for you prompt help! ;p
That should set me on the right track... this["mc" + randomMc].. so simple
Thanks again!
-
Timer
I'm getting an error when calling the timer as stated:
TypeError: Error #1010:
at ad4_fla::MainTimeline/onTimer()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()
Any clue?
-
trace("AKA: Biro Barna");
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
Error calling MC
And the most important part is giving me an error too
Code:
this["mc" + randomMc].play();
is not working? Any clue?
-
Code
My code is the same as your code, I tried what you told me but it's not working.
-
My code
Here it is:
Originally Posted by PlenaryCreation
Maybe something like this:
PHP Code:
// assuming that you have your movie clips on the stage
// and all your movie clips have a generic name of
// mc1, mc2, mc3, mc4, mc5 and so on, you could use
// something like this to achieve your goal
// in the following example, I'll be using only mc1 and mc2
// if you are using more movie clips, just edit the code and
// increase the range of random values
import flash.utils.Timer;
import flash.events.TimerEvent;
var timer:Timer;
var timerDelay:Number = 5000; // set the call delay in milliseconds
var randomMc:Number = 0; // instantiate your randomMc variable
init(); // call the init(); function
function init():void
{
// instantiate your timer object
timer = new Timer(timerDelay);
timer.start(); // start the timer
// handle the timer, call a function on each trigger
timer.addEventListener(TimerEvent.TIMER, onTimer);
} // end of init
function onTimer(event:TimerEvent):void
{
// get a value from 1 to 2
randomMc = Math.floor((Math.random() * 2) + 1);
trace(randomMc); // display the randomly choosen number
// play a random movie clip
this["mc" + randomMc].play();
} // end of onTimer
Good luck.
-
trace("AKA: Biro Barna");
Then make sure that you pasted the code correctly.
I tested my code before posting, it works just fine. In case you edited it and so on, well, I can't guess what did you edit and what you forgot to edit in order to make it work. Create a new Flash file ( that supports AS 3.0 ) and copy paste my code to see if it works ( don't edit it ). It should work, so you only need to see what you changed in it and what you didn't.
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
...
I did copy and paste (numerous times).
I tested the code, and still gives me the error AFTER the delay
(You test, wait 5 seconds, then the error appears).
-
trace("AKA: Biro Barna");
Do you have 2 movie clips on the stage with the instance names of mc1 and mc2 ?
EDIT: TypeError: Error #1010 means that a therm is undefined or does not exist. So make sure that you have 2 movie clips on your stage that have an instance name of mc1 and mc2. Once that's done, it should work, try to understand my code and not only copy-paste it without being sure about what it should do.
Last edited by fx.barrett; 03-25-2008 at 09:17 AM.
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
Mc
Hi!
Thank you for looking at my script and helping out! I appreciate it.
What I modified is this:
Code:
function onTimer(event:TimerEvent):void
{
// get a value from 1 to 16
var mcnumber:Number = Math.round(Math.random() * (16 - 1)) + 1;
trace(mcnumber);
if(mcnumber == 0)
{
mcnumber = 5;
}
trace("all.sq" + mcnumber);
this["all.sq" + mcnumber].play();
// play a random movie clip
} // end of onTimer
I have 1 movieclip on the stage, called all.
Inside that movieclip are 16 other small movies, called, sq1, sq2, sq3, and so on.
I want to tell one of that random movie to play. I thought using: this["all.sq" + mcnumber].play(); would have done the trick. When I trace "all.sq" + mcnumber it returns all.sq4 exactly what I want to affect.
Any clue?
Thank you!
-
trace("AKA: Biro Barna");
Well, you're using it quite wrong.
1) I honestly don't get why are you using Math.round(Math.random() * (16 - 1)) + 1; instead of Math.round(Math.random() * 15) + 1; but whatever, if that makes you feel better
2) if "all" is the name of the movie clip that holds all the rest then you need to use this: all["sq" + mcnumber].play(); instead of what you are using... In your code, you weren't looking inside "all" at all... you were looking for a movie clip called "all.sq1" or "all.sq2" until "all.sq16"...
As I said, try taking it easy, because if you aren't getting this basic stuff then you won't go far... Try reading up on the basics before jumping into the Ocean.
Good luck.
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
-
-
trace("AKA: Biro Barna");
^ Thank, I was thinking about updating it too...
EDIT: Btw, this piece of code is totally useless:
if(mcnumber == 0)
{
mcnumber = 5;
}
Mainly because since you are using this: Math.round(Math.random() * (16 - 1)) + 1;
That " + 1 " assures you of one thing, that no matter what, ncnumber > 1;
Good luck with your projects.
Last edited by fx.barrett; 03-25-2008 at 04:39 PM.
| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro | WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
| Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/ | By perseverance the snail reached the ark. |
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
|