for loop + position mc's

FLASH

    Next

  • 1. Flash 6 support AS2?
    Does Flash 6 support AS2?
  • 2. movieclip._height problem
    I'm having a problem with a simple test case that hopefully someone has run into before. The situation is that I have a text field that I converted to a movie clip called 'letters'. If I hightlight the movieclip and look at the properties window in FlashMX, it tells me the height is 100, let's say. I then add a chunk of code that simply traces the movieclip's height as follows: trace(_root.letters._height); But it does not output 100, it outputs some smaller value and I can not figure out where that value is coming from or how to "convert" it back to the value I expect. Anyone have any ideas? Thanks, Brian
  • 3. math.floor
    New to flash, trying to use the math.floor function. Can anyone explain this strange behavior.... If I put this code on a release function on a button: n = math.floor(0.34343); trace(n); I will get the expected 0. If I use this: s = 0.34343; n = math.floor(s); trace(n); I will get undefined. This makes no sense to me. Thanks for any leads... Jason

for loop + position mc's

Postby hcciii » Mon, 17 Sep 2007 01:29:31 GMT

After attaching movie clips to my stage, I am attempting to reposition each 
clips _x coordinates using a combination for(loop) and onEnterFrame. 

 Because I need to reference each movie clip by name, I use a for(loop) to 
created generate MC names and then store it in a variable called "cp".  I 
attempt to reference the  ._x properties using the variable "cp" but it doesn't 
seem to work.  Any suggestions??

 Here is my code:

 // future arrays
 var nodes:Number = 3

 // position movie clips
 for (i:Number = 0; i < nodes; i++) {
 cp = "box"+i
 this.onEnterFrame = function():Void {
 cp._x += (0 - cp._x)/i+1;
 }; //end onE
 }; //end for loop


Re: for loop + position mc's

Postby hcciii » Mon, 17 Sep 2007 01:33:45 GMT

Here is the entire block of code from which this potion was taken:

 // future array
 var nodes:Number = 3

 //attach movie clips to stage
 for (i:Number = 0; i < nodes; i++) {
 var d:Number = this.getNextHighestDepth();
 var mc:MovieClip = attachMovie("box", "box"+d, d, {_x: Stage.width, _y: i*83});
 }; //end for loop

 // position movie clips
 for (i:Number = 0; i < nodes; i++) {
 cp = "box"+i
 trace(cp)
 this.onEnterFrame = function():Void {
 cp._x += (0 - cp._x)/i+1;
 }; //end onE
 }; //end for loop




Re: for loop + position mc's

Postby juankpro » Mon, 17 Sep 2007 01:39:59 GMT

first of all, this will not work because a movie clip is not a string.
 To reference a movieclip with a dynamically generated name you need to use 
eval or the [] operators. So cp="box"+i should be cp=this["box" + i].

 Second, even if that is corrected the animation will not work because a 
variable can hold only one value at a time. It cannot hols all movieclips only 
the last one. 
 And you are using a single onEnterFrame assignmed meny times to the same clip 
(the root timeline) which does not have any sense either.

 You need to reference each clip, add an onEnterFrame to each clip and use this 
to reference each one.

 The right way to doit is:

 // position movie clips
 for (i:Number = 0; i < nodes; i++) {
 cp = this["box"+i];
 cp.onEnterFrame = function():Void {
 this._x += (0 - this._x)/i+1;
 }; //end onE
 }; //end for loop


Re: for loop + position mc's

Postby hcciii » Mon, 17 Sep 2007 01:49:42 GMT

Thank you.  There is much I need to learn. Little by little I hope to be taller one day! Thanks again.

Re: for loop + position mc's

Postby hcciii » Mon, 17 Sep 2007 10:51:37 GMT

I guess I don't really understand how for loops work.

 Juankpro addressed my original question with this snip of code:
 // position movie clips
 for (i:Number = 0; i < nodes; i++) {
 cp = this["box"+i];
 cp.onEnterFrame = function():Void {
 this._x += (0 - this._x)/i+1;
 }; //end onE
 }; //end for loop

 I thought by making some modifications I could:
 1) position each clip to a different spot ( i*83) and 2) have each clip move 
at a differnt speed ( / i)
 this._x += (i*83 - this._x) / i +1;

 I imagined that the first time the for loop ran throught it the destination _x 
= 0 ( 0*83) at a rate /1 (0+1) and the second time it ran, the destination _x = 
83 at a rate of  /2 (1+1), and so on...

 But instead it all of the clips move to the last number of the for loop so the 
destination _x = 4*83 and the rate /5.  How can I target each instance to have 
a unique destination and speed?

 Can anyone follow my train of thought here??



Re: for loop + position mc's

Postby juankpro » Tue, 18 Sep 2007 00:30:13 GMT

// position movie clips
 for (i:Number = 0; i < nodes; i++) {
 cp = this["box"+i];
 cp._x = 0;
 cp.endX = (i * 83);
 cp.speed = i + 1;
 cp.onEnterFrame = function():Void {
 this._x += (this.endX - this._x)/this.speed;
 }; //end onE
 }; //end for loop



Re: for loop + position mc's

Postby juankpro » Tue, 18 Sep 2007 00:32:06 GMT

When creating this kind of loops you cannot use the original loop variables 
because they will always have the last loop value.

 So the thecnique implies saving a copy of the loop variables into a clip own 
variables and then use this new properties on the onEnterFrame event.


Similar Threads:

1.Looping MC position

Hi,
I have alot of MovieClips and I would like to move all of them to a specific _x,_y coordinates.
Now I use alot of lines by doing it manually (i.e. MC1._x = 400), is there a way to have a loop that will do it automaticlly?
Please note, the MovieClips are not the same so I can't use the duplicate function.
Thanks in advance,
Oren.



2.exact positioning of mc's after full browser resize

I need some help on how to figure out the script for positioning mc's after the 
.swf resizes to fit the browser window.  Some direction, examples or a tutorial 
guide would be great.   Ideally i want to bring an external .swf into an empty 
mc and position that exact center both horizontal and vertical.  any help would 
be greatly appreciated.



3.Getting a mc's X and Y position into textfield

Hi everyone!

I'm often wondering about a mc (sometimes nested) x and y position. To help me I tried to make a textfield to show me this information when the movie is playing. If the clip is moving I will constantly see its position when testrunning my compositions.
I'm only getting the _xmouse/_ymouse into my info textfield but not the position (_x/_y).....


I'm getting tierd of the "NaN" (Not a number) displayed in the textbox:(
Can somebody help me in the right direction?

Thanks






4.attachMovie now I cant access the mc's X or Y position

answered my own question:

this.attachMovie("images_civil", "images_civil_mc", 0, {_x:-25.7,_y:-114.1});

Seems to have fixed it.

5.mc's position control of sounds

I want to create an environment that will be traveled through by a user 
controlled mc. I want the position of the mc to control the volume or trigger 
multiple sound sources ie in a street environment I want the volume to increase 
/ decrease as the user moves by different objects. Is this posible if so how?

6. Dragging and changing an mc's timeline position

7. attachmovie now I cant access the mc's Y position

8. positioning a mc in a scaled mc



Return to FLASH

 

Who is online

Users browsing this forum: No registered users and 29 guest