ActionScript 3.0 :: Using For Loop To Get Objects X Position?

Nov 5, 2009

I have 4 objects that I all want to have their own velocities. I have a bunch of variables (each one has a different value):
PHP Code:
public var vx1:Number;public var vx2:Number;public var vx3:Number;public var vx4:Number;

Rather than having a function for each object to say:
PHP Code:
function1 { this.x = vx1}function2 { this.x = vx2}function3 { this.x = vx3}function4 { this.x = vx4}

I'd like to have a for loop to have my objects x position to += vx(1 through 4):
PHP Code:
for (var i:Number=0; i<5; i++) {
this.x += (vx+[i]);
}

So I tried the above with a combination of " " around different parts of (vx+[i]) but I realized that turning any of it into a string means 'this.x' cannot read it because x has to be a number not a string. So how can I make this.x = vx1 then vx2 and so on with a for loop?

View 2 Replies


Similar Posts:


ActionScript 3.0 :: Change Y Position Of Objects Added With A For Loop?

Oct 29, 2009

here's my code:

ActionScript Code:
for (var i:int = 1; i < 10; i++) {
var symbols = new targetTester();

[code]......

View 2 Replies

Tracking An Objects Y Position?

Jan 23, 2010

I did have previous help with screen movement from Vincent, unfortunately how to get a Variable that tracks an objects Y position on movemnt is eluding me

View 7 Replies

ActionScript 3.0 :: Position Objects By Percent?

Jul 14, 2009

The buttons are all set up in Action Script and not placed on the timeline at all.Here is the code for postion on the buttons.I do not want to move the buttons by PixelsI would like to move the buttons by Perectage so it will look the same on all computer monitors.The person that I am editing the file for would like them in the bottom left of the screen.Here I have moved them by Pixels but these buttons do not appear in the same place on all monitors.

///////let's set the position of
the buttons across the bottom of the screen
b1.move(-350,150);

[code]......

View 5 Replies

Flex :: Position Objects On Different Resolutions

Feb 17, 2010

A Flex project exported as a Projector, showing fullscreen. The project has a background and several dots which each represent a "Location". These locations are fetched from an XML file and have their position set in percentages. The location in pixels is calculated (this works as it should) by the width and height of the Application. The dots are placed correctly. The background is a JPG with a resolution of 1280*1024. At this moment, the background is set on a Canvas with backgroundSize = auto. This places the image in the center without stretching it. Stretching results in ugly, pixelated images and tears the proportions apart.

Problem When we view the project on 2 different resolutions (1 = 1280*1024; 2 = 1024*768), the dots are in the good position, the background image is sharp. But - because of the background having the same resolution as 1, the background isn't fully shown in resolution 2 (because it isn't stretched. A logic result. That's why I tried stretching the background. The results:

[Code]...

View 2 Replies

ActionScript 3.0 :: Ease Objects From One Position To Another?

Jun 24, 2009

I know how to ease objects from one position to another etc, but how do you make it ease position as well as transparency? so it fades in while moving to it's new position?

Code:
var WelTween:Tween = new Tween(welcome, "x", Strong.easeOut, CurMarkXPosWel, 277, 2, true)

is there a way to add like 0% opacity to 100% opacity in the same line of code or do you do seperate?

View 2 Replies

ActionScript 2.0 :: Position Objects In Browser?

Aug 5, 2004

how do you position objects in browser using flash?

View 10 Replies

ActionScript 3.0 :: CSS To Determine Position Of Objects?

Sep 7, 2010

Is it possible to place object on stage with positions read from a CSS file?Basically what I want is to create themes for the application. As and when a different theme is selected, xy position, skins and colors of objects should get applied accordingly.How far its practical? If this is not practical could any one suggest a better way of applying theme

View 1 Replies

ActionScript 2.0 :: Call Loop MC From Different Position?

Jun 9, 2010

how to call loop Mc from different position mean some from left some from right some from up and some from down

i used duplicate movie clip and all mc in loop

View 1 Replies

ActionScript 3.0 :: Change Objects X , Y Position On Each Frame?

Feb 26, 2010

I have a script where i need an objects X and Y Position to change when you enter a certain frame.

On layer 1 i have an input text field with the instance of "message_txt" that runs along all 5 frames in the timeline.

On layer 2 i have 5 frames each with its own actionscript on. The user navigates between frames with simple 'gotoAndStop(4)' etc... on each next or back button.[code]...

View 2 Replies

Professional :: As Objects Change Position On Several Key Layers?

Feb 18, 2011

I have several objects, moveclip, graphics and shapes in several layers keys and want to change position, for example, a moveclip is in the position X: 218 Y:45 and so in other key layers,To change it to X: 240 Y: 50, I go to keyframe for keyframe touch the object and go to properties and change one by one is annoying.Is there any way to do this more quickly at one time in all key frames?

View 1 Replies

ActionScript 3.0 :: Two Sprite Objects - Adjusting Position (X And Y)

Jan 23, 2012

I am trying to do adjustment of position (x and y) of display objects, relative to other display objects. In other words: I have two Sprite objects (rectangle and circle). The rectangle can have their width changed during execution. Yet the circle has a fixed size. What I do is this: regardless of the width of the rectangle, the circle is positioned at the far right of this rectangle.

I tried as follows:
ActionScript Code:
rectangle.width = someValue;
circle.x = rectangle.x + (rectangle.width-circle.width);

In theory it should work, but look what happens:
imageshack.us/photo/my-images/837/positionq.png

As the width of the rectangle increases the distance from the desired location also increases.
Using:
ActionScript Code:
trace (rectangle.width);

I realized that the value of property 'width' does not match the exact amount of pixels that the object is wide. I just did a test and realized that this problem only happens when the rectangle has edge. When the rectangle has only fill, this problem does not occur.

View 9 Replies

ActionScript 2.0 :: Dynamically Create And Position Objects?

Mar 3, 2006

I'm trying to create 49 total objects, each 50x50 px. And position them in 7 rows and 7 columns. I think I must use nested for loops but this is all Ive come up with.

[AS]for(i=1;i<=7;i++) {
for(i2=1;i2<=7;i2++) {
duplicateMovieClip(_root.tMain,"targ"+i+i2,i+i2);

[Code]....

View 5 Replies

ActionScript 3.0 :: Tweening Objects To Specific Position?

May 10, 2011

Right now I'm working on a website that has movie clips that I want to tween back and forth across the stage when a button is pressed.

Here's the idea:

When 2_btn is pressed, I want 1_mc, 2_mc, and 3_mc to move from right to left and then stop when 2_mc is positioned on the stage, stop moving and play

Then if 3_btn is pressed I want all three to be animated from right to left until 3_mc is positioned on the stage, stop moving and play

Then if 1_btn is pressed I want all three to move from right to left until 1_mc is positioned on the stage, then stop moving and play

Basically I have no idea how to accomplish this, or how to word it into Google.

What I have right now, which obviously isn't accomplishing what I want is:

Tween from left to right across the timeline, and then using a gotoAndPlay, and then stop(); on the frame..

View 2 Replies

ActionScript 2.0 :: Checking Current _x Position With A Loop?

Apr 3, 2009

I have this tween function that moves an object 100 pixels as soon as it enters the frame.

if (currentValue % 15 == 1) {
var rab1:MovieClip = rabbit1._x;
var myHoriTween:Tween = new Tween (rabbit1,"_x",Regular.easeInOut,rab1,(rabbit1._x = rabbit1._x + 100),2,true);
myHoriTween.onMotionFinished = function (){
this.stop()
}

My idea is to set up a loop to watch the tween, once it advances its 100 pixels from where it started I want to do a few things before I go to the next frame. Right now I'm using a timer, but it limits my ability to control the playhead.

I've been trying to create a loop to check the current _x and trace it so I can see it advancing as its tweening but it's simply too advanced for me.

View 1 Replies

ActionScript 2.0 :: Loop Doesn't Position Mcs In Right Place?

Apr 29, 2005

i have a loop as follows and the positioning is doing nothing, they are all just standing in one place one on top of the other.

Code:
this.createEmptyMovieClip("thumbHolder_mc", this.getNextHighestDepth());
for (var i:Number = 0; i < 20; i++) {
var thumbnail = "thumb" + i + "_mc";

[Code]....

View 3 Replies

ActionScript 2.0 :: Using A Loop To Duplicate And Random X Position?

Oct 5, 2007

got some code working to duplicate a movieclip, but what I'd really like to do is obviously randomise the movieclip's x position so that it spreads across the stage, rather than stacking in the same position as it is now.

Code:
for (i=1; i<11; i++){
duplicateMovieClip("alien", "alien_new_"+i, 22-10, i);
}

View 4 Replies

ActionScript 3.0 :: Loop For MovieClips To Return X And Y Position

Aug 12, 2010

I'd like to have my movie clips on the stage and run a loop to return their x and y positions, these positions will be stored in an array (startPos:Array) for use later in some other script. I have 7 movieclips on the stage, each with an instance name startobj[a number]

AS2.. Nice all works:
var numberOfElements:Number = 7;
var startPos:Array = new Array();
for (var i:Number = 0; i<numberOfElements; i++) {
var startObjs = eval("startobj"+[i]);
[Code] .....

But when I trace all I get is 0,0,0,0. Is this something to do with in AS3 there is no connection between names and things?

View 5 Replies

ActionScript 2.0 :: Loop Doesn't Position Mcs In Right Place

Apr 29, 2005

i have a loop as follows and the positioning is doing nothing, they are all just standing in one place one on top of the other.

[Code]...

View 3 Replies

ActionScript 3.0 :: Sending Position Of Objects To External Script

Oct 7, 2009

I have a flash script which creates instances of movie clips and stores them in an array. What I want the script to perform next, is when clicking a "save" button the position and the movieclip class name of each created instance will be sent to an external script to store.

View 6 Replies

ActionScript 3.0 :: Sort Objects Depths Based On Their Y Position

Jun 12, 2008

I've been trying to sort objects depths based on their Y position but have not been able to do it efficiently. I was able to successfully sort objects with a selection sort algorithm and a quick sort algorithm; however, both have only been partly successful. Selection sort gets about 8-10/30 FPS with 13 objects and gets about 14-18/30 FPS. This is not good enough as I figure I could have as many as a hundred objects to be sorted at once.

After digging around, I found that array.sort() is more efficient than a quick sort implemented in AS3 and that calling swapChildren() or swapChildrenAt() at every swap was bogging it down. So now I am copying the objects array and sorting it with sort() and then comparing the two and swapping displayObjects so as only to call the swapChildren() or swapChildrenAt() method once per element. It appears to be running, and at full speed, though it won't swap correctly. Here is my code:

[Code]...

View 14 Replies

Actionscript 3 :: Modify Position Of Children Inside Loop?

Mar 3, 2010

I'm trying to make a dynamic image gallery from and xml. From my tutorials, right now i've got it so it will constantly add the next thumbnail below the other, which is fine, but I'm trying to figure out how to make it that once it reaches a certain y coordinate, it will move the x coordinate over and stack them again. So that rather one long list of thumbs, it will be a side by side stack. For some reason, I can't get it in my head how something like this would work. My goal is to have a side by side stack that I will end up putting in a movie clip that will be masked to show only 2 stacks at a time. Then when clicking a button will slide it over. I was planning to use the "movieclip.length" to calculate how far over to move it, but i haven't gotten that far yet. This is what I got:

[Code]....

View 1 Replies

ActionScript 3.0 :: Changing An Objects Diameter Of Rotation Dependant On Position Of Mouse?

Nov 16, 2009

I want the diameter of the 'balls' orbit to change dependant on the position of the mouse but keep the point of rotation exactly the middle of the stage at all times.I.e. if the mouse is hovering over the exact center (both X+Y) of the stage then the 'ball' should have a tiny diameter of rotation (but contstantly follows the orbit in clockwise direction) whilst if you move the mouse towards the edge of the stage then the diameter of the orbit of the ball will increase.Here is the AS which controls a blank movieclip;

var sp:Sprite = new Sprite();
orb1.addChild(sp)
var g: Graphics =sp.graphics

[code]....

View 1 Replies

ActionScript 3.0 :: Change A Objects Diameter Of Rotation Dependant On Position Of Mouse?

Nov 16, 2009

This is for a personal art project, however I have hit a potential (Actionscript) brick wall! I want the diameter of the 'balls' orbit to change dependant on the position of the mouse but keep the point of rotation exactly the middle of the stage at all times. I.e. if the mouse is hovering over the exact center (both X+Y) of the stage then the 'ball' should have a tiny diameter of rotation (but contstantly follows the orbit in clockwise direction) whilst if you move the mouse towards the edge of the stage then the diameter of the orbit of the ball will increase. Here is the AS which controls a blank movieclip;

[Code]...

View 5 Replies

Actionscript 3 :: Position Loaded Images From Loop Based On Image Height?

Jun 10, 2010

I'm trying to dynamically stack images that are being pulled in via an xml file. Below is what I'm doing, and it almost works. The problem is that it only seems to fire off the event complete function on the very last one, instead of going for all of them. Is there a way to make it run the even.complete function for each image?

function aboutfileLoaded(event:Event):void {
aboutXML = new XML(aboutTextLoader.data);
for(var l:int = 0; l < aboutXML.aboutimages.image.length(); l++)

[Code]....

View 2 Replies

Creating Loop To Set Color Objects?

May 8, 2009

I'm trying to create a for loop to set the color objects outlineColor1...100 to the value defined in variable _root.outlineCol. Everything works fine when I set the color to these objects via 100 lines of code but I'd like to replace them with a for loop of course. I suspect the syntax in the first part of the second line is incorrect but I'm not sure.

for (var i:Number = 1; i <= 100; i++) {
outlineColor[i].setRGB(_root.outlineCol);
trace(i);
}

View 2 Replies

ActionScript 3.0 :: Removing Objects Without Using For Loop?

Jul 10, 2009

i am having a problem removing objects from the stage and their associated arrays. basically when a "shark" is added to stage i want all "cans" to be removed and i dont want any "cans" to be added until the shark has left.my problem comes as i dont want to keep using for loops as i already have two or three for "cans" alone and i heard thats not good for the code!

Code:
var canTimer:Timer=new Timer(2000);
canTimer.addEventListener(TimerEvent.TIMER, addCan);
canTimer.start();

[code]....

im not 100% sure were to put this in my code-i didnt really want to put it in a function of it's own as it would mean using another for loop?i get a output error when a shark is added like this:

Quote:

TypeError: Error #2007: Parameter child must be non-null.
at flash.display:isplayObjectContainer/contains()
at dolphinmoviegame_fla::MainTimeline/canHitTest()

even though all "cans" are removed.

View 1 Replies

ActionScript :: Duplicating Objects In A Loop?

Dec 15, 2010

The follow code produces a strawberry image that falls from the top of the screen to the bottom. I tried using a for loop to create 10 different instances of this but it doesn't seem to work for me.(Note: ranx is a number produced randomly earlier in the program)

Code:
var nstrawberry:strawberry = new strawberry();
stage.addChild(nstrawberry);
nstrawberry.x = ranx;

[Code].....

View 2 Replies

ActionScript 2.0 :: Creating Objects In A For Loop

Apr 4, 2007

This piece of code gives me an error because i have an equation on the left side of the equal sign, logically it makes sense, but flash doesn't like the code how would i do some thing like this?[code]

View 2 Replies

ActionScript 3.0 :: Using A For Loop With Hittest Objects

Apr 19, 2012

I'm trying to get something quite simple to work, but can't figure out what's happening here. I have five identical MCs (Bat characters), and the user can drag a bottle to feed them.

There is a hittest object (called WormEat) inside the bat's head. When the bottle, which is attached to the cursor touches the bat's head, it toggles to frame 2 of the bottle, which should play an animation of the liquid going down to empty.

This code is all working fine, except that when the code toggles to frame 2 of the bottle, it remains static. The animated Movie Clip doesn't play.

If not, perhaps a Switch statement could work, but I'm not sure how to use that method with Hittest..

Code:
var DragArray:Array = [Bat1, Bat2, Bat3, Bat4, Bat5];
for (var i:int = 0; i < DragArray.length; i++) {
DragArray[i].addEventListener(Event.ENTER_FRAME, CollisionWorm);

[Code]....

View 14 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved