Flash :: Creating A Function Within A Loop (pointers?)

May 27, 2010

Im trying to create a simple loop that creates 50 buttons, adds them to screen and then when a button is pressed, it traces out that number. I can get it to work by doing stuff I consider hacky (such as using the buttons X/Y location to determine its value), but I'd rather just be able to hold a single value in the function.

The code itself is:
for (var a:int = 0; a < 5; a++) {
for (var b:int = 0; b < 10; b++) {

[code]........

View 3 Replies


Similar Posts:


ActionScript 3.0 :: Flash - Creating A Function Inside Of A Loop?

Jun 19, 2011

create functions using a loop, like so with just the !HERE! replaced with the method of creating it with the 'i' variable. Both the function name in the event listener and the function's setting need to make use of the i variable

Code:
for (var i:int = 0; i <= 5; i++){
this["question"+i].addEventListener(MouseEvent.CLICK, !HERE! );

[code].....

View 4 Replies

ActionScript 3.0 :: Loading Queue / Function Pointers?

Jul 10, 2010

I am trying to implement a queue for loading external assets. Is there a way to make what I am trying to do work?Basically, each time a loading handler function is called, it gets the loaded data and then it calls loadComplete(), which triggers the next function in the loadQueue array.I am able to successfully place a function into a variable of type Function and then call it, but the part where I am adding the variable to an array is failing.

Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;

[code]....

View 3 Replies

ActionScript 3.0 :: Annoying Handling Of Function Pointers

Oct 31, 2010

I'm not sure if you've noticed this, probably not, but function pointers in AS3 run much, much slower than calling the function directly. It's a recent finding, and an annoying one. I use function pointers a lot. An obvious example would be to easily change the behaviour of a certain object. Say I have a class that controls movement, it has a class level function variable called UPDATE (ie public var UPDATE:Function), and 3 or 4 actual functions it can point to.

This always me to quickly/easily change the behaviour of an object. Say for example I want an object to run on different movement code once it's collided with something, I can just do UPDATE = movement2; etc. However, a pointer for a function runs about 15 times slower than running the function directly, therefore I need a replacement. And I really have no idea why there is this absurd disparity in speed between the 2. With some variables, accessing a reference is faster than accessing the variable directly, obviously not with functions. What would you advise as a nice, simple replacement solution for the above example?

View 14 Replies

ActionScript 2.0 :: Creating Multiple Function() With A Loop?

Sep 3, 2006

Code:

for (var i:Number = 0; i<12; i++) {
var myFunction_i:Function = function () {
trace("This is function "+i);
};

[code]....

I'm needing to create identical functions but different 'i' Number Variables so that I can call them as shown when I need to.

View 8 Replies

ActionScript 2.0 :: LoadInit Function When Dynamically Creating Movieclips In A Loop?

May 29, 2008

I using a loop to dynamically create some movieclips and then position them using the ._height and .width values.

When they are created I use a Listener and LoadInit, to check that everything has loaded. I do this because I want to be able to access the ._height properties of the movieclip in order to place them next to each other and centre them vertically.

If I place the following 3 lines outside the function:

inBead._x = currentPosition;
//gets the start position
currentPosition = currentPosition+Number(mainLoader._width);
//gets the position and adds the width of the movieclip

[Code]....

View 1 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

ActionScript 1/2 :: Creating A Sound Loop In Flash?

Jun 16, 2011

I found an issue when I was creating a sound loop in Flash. I'm using similar code (here is a short version):

[Code]...

View 6 Replies

ActionScript 3.0 :: Flash Creating MovieClip Instances In Loop

May 28, 2010

So I know that if I want to create an instance of a movie clip called part01Roads from the library I do this:

Code:
var part01Roads_mc:part01Roads = new part01Roads();
addChild(part01Roads_mc);
part01Roads_mc.x = -22379;
part01Roads_mc.y = 317;

Well I want to take this one step further if it is at all possible. Lets say I have 100 different movie clips labeled in a sequence: part01Roads, part02Roads, part03Roads ..... part100Roads. Instead of rewriting the above code 100 times, can I make a loop to do this?

View 13 Replies

ActionScript 3.0 :: Flash - Creating A For Loop To Create Dynamic Variables?

Dec 6, 2010

I have the code below but I need to generate it with a for loop. What is the proper way to do this? I don't initially know how many points i will have. I just want to create a for loop to loop through a variable that holds the point count such as "var totalPoints=10"

//1
var p1oint = new Point();
points.addChild(p1);

[code]......

View 1 Replies

IDE :: Looking To Get Some Pointers On A Game?

Jun 17, 2009

Mainly looking for pointers to the tutorials I am sure exist (but which I can't find). But I am also very open to any general or specific advice you may have to spell out for me in the thread. I am looking to build a PBBG (Persistent Browser Based Game) which, while single player, has some few multiplayer elements. Indirect interaction. One example of this is a commodities market - yes, the good old space trading, fly to one planet and buy, fly to another and sell scenario. I want every player to impact the inventory of each planet, and to have that inventory affect the buy/sell margins, etc. Other Indirect interaction would be bars et al, where players can chat, maybe (a BIG maybe) trade inventory and such. It seems direct, but it is not fighting one another or fighting at each other's side, etc.; so to me it is 'indirect' to the game. But that isn't why I'm here (feel free to impart any wisdom you have anyway, if you so desire); just an aside to explain a bit about the game.

[Code]...

View 1 Replies

Flash - Calling The Function Within That Function And Later Stopping The Loop - Starting And Stopping Functions?

Jan 7, 2012

I am making a character walk. This code will make him wobble to the right and when thats done it will trigger him to wobble to the left and then call the function again to continue the loop.I can get the loop to work fine by calling the function but how do I STOP the function? Also I want to call it later on. Is there a way to start and stop a function?

function wobble()
{
var ws = .1;
var dis = 1;

[code]....

View 2 Replies

Make A Clock With Hand Pointers?

Oct 20, 2011

I'm thinking of making a simple clock design and adding hand pointers that tell the time.
 
a)how hard is it to add action script to the hand pointers?

b)can i use the clock on my desktop to show time?

View 3 Replies

Actionscript 3 :: Concept Similiar To Pointers In As3?

Jan 24, 2012

Is there a concept of pointers or anything similiar to that in as3?

I have used a concept of

var mc1:MovieClip;
var mc2:MovieClip();
var mcCommon:MovieClip = new MovieClip();
mcCommon["myptr"] = mc1;
mcCommon["myptr"] = mc2;

Where would I get to read and learn more about this concept. I'd like to get simple answers, as I am not an expert in as3. I'm still learning.

View 3 Replies

ActionScript 2.0 :: Pointers With Calculator-like Interface?

Jul 27, 2009

Need pointers from the good folks here. I need to create an interface illustrated in the link below:

Calculator-like interface (GIF)Scenario 1) When the user clicks either the button 30 or 60, it will update dynamic textfield (value1) with the corresponding value 2) When the user clicks either the button 45 or 73, it will update dynamic textfield (value2) with the corresponding value

3) Dynamic textfield (output) will dynamically add the values of 'value1' and 'value2' and generate the total.

How do I go about scripting the interface?

View 1 Replies

Pointers For Designing Simple Interactive Game?

May 13, 2009

I'm looking to build a very simple (hopefully!) interactive game.

- A number of balls are situated at the bottom of the stage.

- There are several dropzones which the balls can be placed in.

-Once a dropzone is occupied with a ball, its not possible to populate that the dropzone with another ball until the present one has been removed. -Depending on which balls are present in the dropzones, the balls animate differently. the red ball is placed in a dropzone.  There are currently no other dropzones populated with a ball.

[Code]...

View 5 Replies

Creating A Fully Function Iphone In Flash?

May 5, 2010

im having trouble creating a fully function iphone in flash and create user interaction witht he app.how to do this i have create the different app stages and how they look in photoshop

View 5 Replies

ActionScript 2.0 :: Creating A Search Function In Flash?

Nov 22, 2005

I have this long list of video files(some 500 of them) to be linked to my flash interface. I am looking at the option of creating a search engine such as that when the user key in some keywords, it will search thru my list of video files and bring up the appropriate files. (results will show names of files first then user can choose to click on those that they want to view)

View 8 Replies

Flash 8 :: GotoAndPlay - Loop Function Between Frames

Jun 13, 2011

I am working with some actionscript that are spread out amongst different frames, and having changing conditions, determines whether to end the sequence (gotoAndStop(1)) or continue (gotoAndPlay(5))

(For easy example):
frame 4=
x=1
frame 5 =
x=x+1
frame 6 =
if (x=10){
gotoAndStop(1)
}else{
gotoAndPlay(5)
}

I understand this easy example could be done several ways on one frame easily, (while x<10, etc).. but my code is so long and complicated, that the way I wrote it, it was easier to have it sort of "loop" between frames. The problem with this is, I think the frame jumping is slowing the coding down. I tried functions, (like having all coding in frame 5 as a function, then calling that function with the "else" in frame 6), but that would only run the function once.. I need it to keep looping.

View 2 Replies

Flash - Using Array And Loop / Push Function

Apr 2, 2011

what I'm trying to do is to get 4 movieclipps (leaf1, leaf2, leaf3, leaf4) to play the sound that is attached to them when is dragged onto another movieclip (NatureTarget) and the play button is pressed so that the sounds are played in the order they are dragged on. I know I need to use an array and the push function and a loop...

View 1 Replies

Flash :: Pass Strings To Function In A Loop?

Mar 25, 2009

I have this code that activates when rollover, rollout, and release. I functions for rollover and rollout works, but the release function does not. I'm trying to pass some strings with url's to the function within a loop.

var url1:String = "http://www.google.com";
var url2:String = "http://www.google.com";
var url3:String = "http://www.google.com";

[Code].....

View 2 Replies

ActionScript 2.0 :: For Loop OnRelease Function [Flash CS3]

Jul 14, 2010

I have another question about my For loop. I am designing and coding a navigation menu at the moment, and so far I have got the button instances to duplicate for each of the menu items, and set widths, positioning values and RollOver/RollOut functions. However, I would ideally like to include the onRelease button functions in the for loop too - as they are all the same apart from the variable "i". Here is the code snippet:

[Code]...

View 2 Replies

ActionScript 3.0 :: Flash - Loop Addeventlistener Function?

Aug 24, 2011

I have a script that contains:an array of movieclips -> MaxBallArranother array of movieclips -> MaxBallLrgan array of textfields -> MaxToolTipArra library movie clip -> max_boxI'm trying to gather them some how in an addEventListener which worked fine in that way:

Code:
MaxBallArr[0].addEventListener(MouseEvent.MOUSE_MOVE, MaxshowNav)
MaxBallLrg[0].addEventListener(MouseEvent.MOUSE_OUT, MaxhideNav)

[code].....

View 6 Replies

ActionScript 3.0 :: Flash AddEventListener In A For Loop And Value Keeps Coming Back The Same For The Function

May 31, 2011

This code keeps coming back with the same value for i when the button is clicked. It is looping through but only the last value gets passed.

[Code]...

View 1 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

Creating 10 Functions Using For Loop?

Feb 25, 2012

I am trying to create functions using a for loop for my buttons' over and out listeners.I would like to stick to a naming convention but it does not seem to work. I am trying to create 10 buttons with function names like btnOver1, btnOver2, etc...

Code:
for(var i:int=0;i<=9;i++){
function btnOver[i](e:MouseEvent):void{

[code].....

View 1 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

Creating Variables Dynamically Within A For Loop?

Jan 24, 2010

I need to make new sprites on-the-fly within a for loop, and this code does not work:

Code:
for(var i:int = 0; i<5; i++) {
var this['menuBtn'+i] = new Sprite();

[code].....

View 2 Replies

ActionScript 3.0 :: Creating AddEventListener Within Loop?

Jan 14, 2009

Everything works fine except MouseEvent.CLICK addEventListener.menuInfo variable contains part of defined instace name.cURL contains full URL to link.If I trace menuInfo variable, it outputs correctly in order as I exptected.But last event overwrites everything to last element of xList (contains XML list).How do I make this work correctly

Code:
function createMenuEventListener(xList:XMLList):void
{

[code].....

View 1 Replies

ActionScript 3.0 :: Creating Loop In Timeline?

Oct 21, 2009

My master timeline is 128 frames long, I want the timeline to play from frames 1 to 128 once and then from frames 64 to 128 three or four times before returning back to frame 1 and starting the whole sequence again so I end up with a continuous loop that consists of the full animation once and the second half 3-4 times all repeating endlessly. I've been reading about "for" loops and guess this is what I need to use but I don't quite get how to set it up, how I'd set up a counter to count the repeats, and how it would reset etc.

View 5 Replies







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