ActionScript 2.0 :: Function Created In For Loop?

Mar 1, 2008

I have the following code that should set the onPress events for movieclips

Code:
function actionSetter() {
for(var k = 0; k< 5; k++) {
trace(k); //traces correctly
_level0["EventBtn" + k].onPress = function() {

[Code]...

What should I do to correctly define onPress for my movieclips within the loop?

View 2 Replies


Similar Posts:


ActionScript 2.0 :: Function Only Working On Last MovieClip Created Within Loop?

Aug 2, 2008

As the title suggests, I cant get function at end of the code to attach to each MovieClip I create dynamically within a loop.Only the last image will follow the mouse. What am I doing wrong? Im really not sure.

Code:
//now do something with the xml data
PopulateLists = function(final_array)

[code]....

View 4 Replies

ActionScript 2.0 :: Place A For Loop In A Recursive Function With The Function Call Within The Loop

Nov 4, 2005

If you place a for loop in a recursive function with the function call within the loop... will the loop finnish or does it stop working untill the last recursion?

View 2 Replies

Created Mask And Want It To Loop?

Jul 26, 2011

I am doing is learning flash, so what I have done is followed some tutorials and created some different images with a mask, now I trying to make them loop and I can't seem to figure out how to do it. it seems at the end of the tutorial it says I must put in a stop or the last layers do not come in to view. So I am curious as to how to get passed this problem I am having. am I doing this completely wrong?

View 1 Replies

Reference Instances Created By A Loop Elsewhere?

Jan 20, 2010

[code]My code will:

- loop through the Grid array and place each tile on the stage

- assign RedBall a random Grid coordinate and places it on the stage at that coordinate

I want to be able to click RedBall, which will create a border around the tile beneath RedBall, and create borders around the tiles above, below, to the left and to the right. BUT, I don't want to reference the tiles by their distance in pixels from RedBall or from each other; I want to reference the tiles by their coordinates in the Grid array. So I want to:

- get the coordinates of RedBall

- use those same coodinates to reference the tile at the same coordinates in the Grid array

- use the tile's coordinates to reference the tiles above/below/left/right

- apply a border to all these tiles

What's the best way to reference an instance of a tile? Should I apply a name to each instance as it's created in the loop? like myTile.name = "tile"+i+"_"+j; ? If so, how do you reference that instance later? Just tile1_3 ? Do you have to prepend it with root, or stage, or the class it was originally created in? Do you have to use getChildByName? OR, can you still reference it later without having given it a name?

View 1 Replies

ActionScript 2.0 :: MCs Created In A Loop Are Disappearing?

Nov 21, 2010

I have a simple gallery site with thumbs 'gridBtns' that show and hide content pages 'projectPages'

I have a loop that duplicates an MC (projectPageHolder) (that already exists on the stage) 20 times, simple enough. I run a trace that confirms they all exist.

In the same loop I give a different set of 20 MCs (gridBtn) an onRelease function that attempts to show and hide the projectPage MCs using _alpha, again simple enough.

For some reason the first 4 MCs disappear...they do not trace or become visible, but the rest are fine.

[Code].....

View 1 Replies

ActionScript 3.0 :: Cannot Control Mcs Created By A Loop?

Aug 25, 2009

simplied version:(there's a mc of the Box class in the library)

Code:
for (var i:int=0; i<10; i++) {
var box:Box=new Box();[code]......

error: access of undefined property box2

View 13 Replies

ActionScript 3.0 :: Referencing Loader After Created In Loop

Nov 11, 2010

I am creating a loop which loadsimages to newly created loaders.After each loader completes, I'd like to pass it through another function.[code]It seems like if the above function was my complete_handler but in the place of loader_names[k] would be the completed loader.

View 5 Replies

ActionScript 3.0 :: Remove Many Textfields Created By A Loop?

Nov 8, 2011

I have a loop which creates several TextFields in different positions[code]..
 
I have tried removeChild and setting the t.text to nothing, but this only affects the last created textfield

View 10 Replies

Actionscript 3 :: Referencing Loader After Created In Loop?

Nov 11, 2010

I am creating a loop which loadsimages to newly created loaders. After each loader completes, I'd like to pass it through another function Here's my loop of loaders where loader_names is an array of my loader names and overlay_files is an array of my file URLs

for (var j:int = 0; j < loader_names.length; j++) {
loader_names[j] = new Loader();
loader_names[j].contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader_names[j].load(new URLRequest(overlay_files[j]));
}

Once each image loads I want to overlay the image on a map here's a loop which does just that, only I do not know how to pass loaders into this function as they finish

function create_overlays(e:Event):void {
for (var k:int = 0; k < loader_names.length; k++) {
overlay_names[k] = new GroundOverlay(loader_names[k],
new LatLngBounds(new LatLng(46.669, -115.035), new LatLng(48.995,-112.079)));
}
}

View 1 Replies

ActionScript 3.0 :: Access To Childs Created Through For Loop?

Nov 15, 2009

Image's paths are in the xml file. I make a loop to load images to the Display List.
So if i have a loop:

ActionScript Code:
for(var i:int=0;i<xmlList.length();i++)[code]....

after it is done i would have access only to the last imageLoader instance. How to get access to the rest of images, which were added to the Display List with the same name "imageLoader".I tried to call it with the imageLoader.name property,but surely i do something wrong, as only errors appear in the output panel.

View 1 Replies

ActionScript 2.0 :: Loop Externally Created Movieclip?

Dec 2, 2010

I have a horizontal scroll bar that I need to appear to loop around continuously. I've managed to get it moving on its own since the last time I posted, however the loop is proving more difficult.

The move function is here:

Code:
public function movemouse() {
lst.onEnterFrame = function () {
var speed:Number = -1;
this._x += speed;

[Code].....

View 1 Replies

ActionScript 3.0 :: Access Objects Created In A For Loop?

Jan 21, 2011

I need to be able to make a large amount of concentric circles, using only the action script. I need to be able to alter each of these concentric circles independently from each other. Currently My code is as follows:

ActionScript Code:
var circ1:MovieClip = new MovieClip();
addChild(circ1);

[code].....

View 6 Replies

ActionScript 3.0 :: Accessing Items Created In Loop?

Mar 14, 2012

If you have a series of sprites created in a loop:

ActionScript Code:
for (var i:int = 0; i < numItems.length(); i++) {
var mySprite:Sprite = new Sprite();
}

Which you added event listeners to, in the same loop:

ActionScript Code:
for (var i:int = 0; i < numItems.length(); i++) {
var mySprite:Sprite = new Sprite();
mySprite.addEventListener(....
}

How can you remove those listeners, then add them again? I need to kill and re-enable the listeners of many sprites which were created that way.

View 4 Replies

ActionScript 3.0 :: Reference Instances Created By A Loop Elsewhere?

Jan 20, 2010

My code will:

- loop through the Grid array and place each tile on the stage
- assign RedBall a random Grid coordinate and places it on the stage at that coordinate

I want to be able to click RedBall, which will create a border around the tile beneath RedBall, and create borders around the tiles above, below, to the left and to the right. BUT, I don't want to reference the tiles by their distance in pixels from RedBall or from each other; I want to reference the tiles by their coordinates in the Grid array.So I want to:

- get the coordinates of RedBall
- use those same coodinates to reference the tile at the same coordinates in the Grid array
- use the tile's coordinates to reference the tiles above/below/left/right
- apply a border to all these tiles

What's the best way to reference an instance of a tile? Should I apply a name to each instance as it's created in the loop? like myTile.name = "tile"+i+"_"+j; ? If so, how do you reference that instance later? Just tile1_3 ? Do you have to prepend it with root, or stage, or the class it was originally created in? Do you have to use getChildByName? OR, can you still reference it later without having given it a name?

View 3 Replies

ActionScript 2.0 :: Loading Into Clips Created By For Loop?

Nov 28, 2008

why this won't work?

Code:
var base:MovieClip = this;
// initiate

[code].....

View 1 Replies

ActionScript 3.0 :: Animating Instances Of An Object Created By A For Loop?

Dec 25, 2009

I'v been toying with this for a few weeks now and I'm trying to find the best way to animate several instances of an object created by a for loop thru an ENTER_FRAME function.When the function runs only 1 of the 3 instances that were created animates.

var balloonArray:Array = new Array();var balloon: hotAirBalloon;var xVel: Number = -3;var yVel: Number = -4;
addEventListener(Event.ENTER_FRAME, startBalloons)

[code]....

View 9 Replies

ActionScript 3.0 :: Removing Multiple Child Created By For Loop

Dec 8, 2011

I'm creating buttons like so:
for (k=0; k<5; k++) {
myLink = new LinkClass();
myLink.name = "link" + k;
box.boxMC.linksMC.addChild(myLink);
}

This creates 4 movieClips with the names "link0", "link1", etc. How do I remove them? I try this:
box.boxMC.linksMC.removeChild(myLink);
But it just removes the last one made (link3). How do I have all of them removed?

View 2 Replies

Flash :: Remove Timer Of Object Created In A Loop

May 19, 2011

I want to remove an object that is created in a loop, with a timer.

var timer:Timer = new Timer(2000);
timer.addEventListener(TimerEvent.TIMER, voegtoe);

In function voegtoe I'm adding an Movieclip Object called man:

man.x=Math.random()*650;
man.y=Math.floor(Math.random()*(70))+350;
addChild(man);

I want to remove this object after 2 seconds. The problem is that there are multiple 'man' objects.

View 3 Replies

ActionScript 3.0 :: Controlling Multiple Children Created In For Loop?

Nov 15, 2011

So I'm working on a Flash version of the old "Robots!" game. In case you're not familiar: the game lays out a number of robots on a grid (number varies by level), and drops the player in the middle. As the player moves around the grid, the robots all move towards the player one grid space per player move. The object is to destroy all the robots by making them run into each other (or the rubble left from previous collisions) without letting a robot run into you.

Anyway, my robot hordes are being created on the stage through a "for" loop, and each icon is a child of variable "evilBot" which references a library item with the class name "enemy."

ActionScript Code:
function placeBots():void{
for (var c = 0; c < numBots; c++){
evilBot = new enemy;

[Code]....

I've run a trace on "evilBot.name" and verified that the children are being given instance names of "evilBot0, evilBot1 ..." and so on. But no matter what I try, I can't issue instructions (regarding movement, orientation, etc) to individual children.

Using a for loop and "this["evilBot" + x]" returns a "term is undefined" error.

If I store the instance names in an array (named "botName") and use "evilBot.name[botName[x]]", I get the error "Property evilBot0 not found on String and there is no default value."

View 9 Replies

ActionScript 2.0 :: On Press - Accessing Buttons Created With A Loop?

Sep 27, 2007

I have generated a series of buttons using this:

Code:
duplicateMovieClip(sign, "sign"+z, z)
while still inside the loop that is creating the buttons I can get to each sign:

[code].....

View 3 Replies

ActionScript 3.0 :: Associating A Loop Variable To Objects Created In It?

Jun 3, 2009

I create some movieclips dynamically through a loop and store them into an array. I add an event listener to all those movieclips. In the function to which I direct the listener I want to be able to get the loop variable value associated with each movieclip. For example if you click the movieclip that was created the first time the loop ran then you would get the value 0.

Hope I have explained myself well enough. Is it necessary to create a custom event class for this?

[Code]....

View 3 Replies

ActionScript 3.0 :: Unique Names For TextField Created In For Each Loop?

Jun 23, 2010

I have an for each loop that creates a new textField for each item and I need to know how you can give each textField a unique name so it can be targeted later on.Here is the relevent code:

Code:
var i:int = 1;
for each (var titleElement:XML in titleList) {

[code].....

View 3 Replies

ActionScript 3.0 :: Flash Naming TextFields Created Using Loop?

Jan 17, 2011

what is the syntax for assigning names to textfields created dynamically using a loop.

Code:
for (var i:uint=0; i<10; i++) {
var myText:TextField = new TextField();
myText.defaultTextFormat = textFormat;[code]....

As expected, this code gives me a warning "Duplicate variable definition".How can I assign names dynamically (myText1, myText2, myText3...)?

View 3 Replies

ActionScript 2.0 :: Created A Grid With Over 200 Movie Clips Dynamically Using A For Loop?

Dec 9, 2005

I've been staring at the screen too long and I'm sure the answer is simple but this has been bugging me for a bit now. I've created a grid with over 200 movie clips dynamically using a for loop. I was wondering if there was a way to assign rollovers and such to each new clip using the same loop.

I've been poking around with it a bit but can't seem to get it working and sure don't want to write over 200 rollover functions so any help would be great.

View 7 Replies

ActionScript 2.0 :: Multiple ColorTransform Object Instances Not Created In Loop?

Dec 17, 2006

I thought this would be simple but for some reason I'm having all kinds of problems. Why won't the for loop create a new c instance each time the loop increments, like it does for sHolder and s? ...And, assuming it is possible to make it do this, how can each instance be given an identifier that can be accessed dynamically, like sHolder and s in the traceSomething function?

Code:
package {
import flash.display.Sprite;
import flash.geom.ColorTransform;

[Code]....

View 12 Replies

ActionScript 2.0 :: Keeping The Data Parameter Of The Object Created With A While Loop

Mar 7, 2004

i've been struggling with the following:

i am creating a list of buttons with an attachMovie. the AS is :

//as
var i = -1;
while(++i<userlist.length){
var user = userlist[i];

[Code].....

okay the problem is this: then i assign an on click function to every button right in the while loop that uses the data parameter of the "ob" object and when i play the movie the data parameter is always the parameter of the last object created for all the buttons. I know why this is happening- it overWrites the old "ob" with the new with every itteration of the loop.

But how would i go differently about creating an individual "ob" for each button created and still be able to have a function with a data parameter like this.onRelease.userClicked(data)?

View 9 Replies

ActionScript 2.0 :: Using Var From For Loop In Function Outside Of Loop?

Nov 2, 2009

I have a variable in a loop that i want to access in a function outside of the loop. However the variable gets deleted when the loop is closed so no longer exists when i call in the function.here is the code; i'm trying to access the variable picHeight from within the scroll function

Code:
pauseTime = 3000;
xmlImages = new XML();

[code].....

View 3 Replies

ActionScript 2.0 :: Object Created By A Function

Aug 20, 2009

why can't i acces the object outside of the function with test1._alpha = 20;[code]

View 4 Replies

ActionScript 3.0 :: Recalling An MC Created In Another Function?

Feb 14, 2010

I don't really know what is wrong with the script...

ActionScript Code:
port_BTN_0.addEventListener (MouseEvent.ROLL_OVER, rolloverMCfunc);
function rolloverMCfunc(event:MouseEvent):void
{

[Code]..

So, basically I am making a mc to come inside the stage (rolloverMC_0) when I rollover over another MC (port_BTN_0). But when i rollout, it doesn't seem to work and it gives an error.

View 3 Replies







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