flash function Q
- Started
- Last post
- 20 Responses
- vaporstouch
i am trying to multiple instances of a MC from my library, and make them move back and forth on my stage at random speeds. i have 2 problems
1) i cant get this to work without using '_root'. i need a relative path solution because this witll be loaded into a _parent swf
2) the blocks added all move at the same speed, i want to give them each their own random speed
here is the code so far, me and my deadline thank you for your help:
//interval ID
var loadBoxes;var current = 0;
//max num random boxes
var maxBoxes = 5;loadBoxes = setInterval(boxIn, 10);
function boxIn() {
_root["speed" + current] = Math.ceil(Math.random() * 5) - 2;if (current (less) maxBoxes) {
attachMovie ("box", "box" + current, current + 180);_root["box" + current].onEnterFrame = function() {
currentPosx = this._x + _root["speed" + current];
//trace(_root["speed" + current] + " speed");
this._x = currentPosx;
if (currentPosx(less)(0) || currentPosx(greater)(748-this._w... {
_root["speed" + current] = -_root["speed" + current];
}
}
current++;
} else {
trace ("done");
clearInterval (loadBoxes);
}
}thank you!
- ok_not_ok0
link up the FLA
:)
- System-Idle0
once you have attached and duplicated the mc's cant you use _level to target them.
when dup'ing the mc's I would asign them a random var which would be thier speed, then in yr func extract the mc var for each iteration. ( prob use a for loop also)
- vaporstouch0
thanks for the input. so if i have
attachMovie ("box", "box" + current, current + 180);
(180 is a random # to make sure the level doesnt conflict with other stuff in the swfs) how do i target that level?
_level[current + 180]["box" + current]._x
?
- vaporstouch0
*bump please
- jkosoy0
Why target the level? Just assign a variable to the movie you're attaching.
// note: I use dollar signs to differentiate between global and local variables.
var $mc = attachMovie ("box", "box" + current, current + 180);
$mc._x = // do whatever you want.
- System-Idle0
sending some mail.....
- System-Idle0
check yr mail box.
- vaporstouch0
thanks a lot for the email, but i am afraid i am still working in MX, no '04. i couldnt open the .flas. thanks anyway
- vaporstouch0
isnt there a way to assign a variable reference to a timeline to avoid problems when loading it to another swf? i read that somewhere.
- System-Idle0
have sent mx version
- unfittoprint0
never target levels.
target movieclips.never target _root.
use relative paths [ie: _parent, _parent._parent, this]
- System-Idle0
i'm of for some din dins
catch up laters
- vaporstouch0
thank you system, i am checking it out now!
unfit, i am trying to use relative paths, cant figure it out with the code in my first post. can you shed some light?
- System-Idle0
even though you are attaching movie clips to levels, they are all still in the same swf. _level
therefor you can use _level0.mc1._x
_level0.mc2._x
etc
- System-Idle0
thats a good way of working Unfit, keeps it simple, does that work across swf levels
- System-Idle0
vapor
any joy with those files
- Mick0
If you want to use _root, think about using _lockroot
- vaporstouch0
thanks, just sorting through them (got pulled to do something else). i am used to working with 'this' and '_parent' targeting variable/MCs, so the levels are a bit new. but thanks a lot System!
- System-Idle0
no probs