ActionScript 3.0 :: Creating Functions With Variables Using A Loop?

Dec 11, 2010

I've created a basic function that sets a movieclip to a certain state depending on which mouse cursor is set (determined by a variable called txt_cursor). I can hard code this to work great for the one single movie clip but potentially have to do this for 624 other movie clips so obviously want to create a for loop to reproduce this.

Code:
chk1.onRelease = function()
{

[code]........

View 1 Replies


Similar Posts:


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

ActionScript 2.0 :: Dynamically Creating Functions Inside A Loop?

Dec 8, 2011

After loading the movieclips and text boxes dynamically I now need to get the movieclips to perform a unique function when they are pressed, for testing purposes I am using the getURL funciton and linking to the boxNo. This is just so I can see what is going on!At the moment they are all linking to the boxNo that is pulled from the last run of the loop.

for (var i = 0; i < loc.length; i++)
{
var boxNo = loc[i].location_ID;;

[code].....

View 1 Replies

Actionscript 3 :: Creating Anonymous Functions In Loop With Not The Same Arguments

Dec 25, 2010

I want to make in loop set of buttons, and add to them some events, but anonymous functions is the same. I write example code:

for(var i:int=0;i<5;i++)
{
var button:SimpleButton = new SimpleButton(...);
...

[Code]....

And I want to trace 0,1,2,3.. from click buttons instead of 4,4,4,4 ..

View 1 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 Dynamically Named Variables In A For Loop?

Nov 4, 2009

i am loading several images from an XML path into a flash movie and i want to dynamically create image loader variables for them. Here is my code so far:

Code:
var xmlData:XMLList;
var myXML:XML;
var xmlLoader:URLLoader = new URLLoader();

[Code]....

method and this doesn't work for me either, i'm guessing thats because it is in the AS2 forum.

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

ActionScript 2.0 :: Creating Variables In A Loop And Assigning Them Non Empty XML Values

Jun 1, 2011

Here is the structure of the XML file: PHP Code: <xmlfile><page></page><page> <source></source> </page></xmlfile> Some "page" nodes contain the extra "source" node. What I'm currently doing is looping through all the page nodes and looking for any source nodes. If there is a source node, I create a variable, and want to assign it a value of the contents of the "source" (HTML).

[Code]....

View 1 Replies

ActionScript 3.0 :: Array Of Variables - Make A Bunch Of Variables From A For Loop

Feb 21, 2009

How can I make a bunch of variables from a for loop. for example for (var i=0; i<total; i++) {var bunch(i);}. that i make a bunch of variables named bunch1, bunch2, bunch3. I keep getting errors. I program and use so many different languages that I dont know if that can be done with AS3. my only other alternative i can think of is to create some sort of event dispatcher object array. but I dont know how to get them all to send events to one listener with there index number.

View 5 Replies

ActionScript 3.0 :: Accessing Loop Variables Outwith Loop

May 5, 2011

Say, I had a loop in a function...

[Code]....

How would I refer to a in another function

View 8 Replies

ActionScript 2.0 :: Dynamically Creating Functions?

Jul 6, 2003

how would i go about dynamically making a function... im making a Tile Based World level editor and when the user is done editing a level, then they hit a button and a couple of for loops runs through all the tiles checking the x,y and tile type. then i want thisinformation to be parameters within sub functions within the main function. so the as would look something like this

[AS]subFunction = function () {
//do this
}

[code].....

View 2 Replies

AS3 :: CS3 - Calling Variables From Other Functions

Aug 20, 2009

If I have a function and I want to call a variable from another function (only 1variable), how do I do it? I know in the olden days you could set the variable to local or global, but that does not seem to work anymore. There is only 1 variable I need access to, but all the tutorials I have come across talk about making classes for multiple variables.

e.g. function2();
{
variable_b = variable_a;
}

[Code].....

View 3 Replies

Dynamic Variables In A Functions?

May 8, 2010

Why does this not work???

Code:
function myFunction(val0,val1,val2){
trace(this["val"+0);
trace(this["val"+1);
trace(this["val"+2);
}
myFunction("hello","test","hi")

All i get is undefined. If i just put "trace(val0)" i will get "Hello" -- so i cannot work out how to get the value of the dynamic variable inside hte function?

View 4 Replies

ActionScript 3.0 :: Variables Used In Functions

Mar 16, 2012

I got this variable:[code]is there a possibility that the compiler gets confused because my variable has the same name like the functions's parameter (type = type)? i'm not certain about this topic. Normally I'd write my function's parameter like this (if such a case occurs):[code]just to make sure the names do not exactly match.

View 3 Replies

ActionScript 2.0 :: Variables In Functions?

Nov 16, 2005

I can't figure this out.

Code:
function createTextBoxes() {
for (var n=0; n<caption_obj.textXML.length; n++){[code].....

The XML portion is working fine. What I'd like to be able to do is access the created text fields outside of the function. For example:

captions1.alphaTo(0,1,"linear",1);

This works fine when it's inside of the function, but outside of it, it won't. Basically I need to time the captions to things that are happening in an animation. The animations are also tween driven, so it would be something like obj_mc.tween("_x", 200,2,"linear", 5,fadeOutCaption1); with fadeOutCaption1 being a function that fades out the first caption and brings in the second. If there is a better/more effecient way of doing this let me know.I also can't seem to apply any styles to the text field. Do I need to create an array or object with ["captions"+n] and then pull from that?

View 2 Replies

ActionScript 2.0 :: Assigning Functions Via A Loop

Jun 21, 2004

I am working on a page where three differnt buttons effect one movie clips properties, the one movie clip will go to its rollover state when any of the buttons are on rollover, hmm, that sounds about right] i have assigned functions within a loop and the rollovers, rollouts and instance in the loop have been defined for all but the movieClips dont go to the right place. the code i have used is this....

[Code].....

View 3 Replies

ActionScript 3.0 :: AddEventListener Functions With A For Loop?

Nov 17, 2010

I have four buttons with eventListeners that call four different functions. Each function name starts with the button name. like this:

Code:
btn1.addEventListener(MouseEvent.MOUSE_OVER, btn1function);
btn2.addEventListener(MouseEvent.MOUSE_OVER, btn2function);
btn3.addEventListener(MouseEvent.MOUSE_OVER, btn3function);

[Code]....

View 2 Replies

ActionScript 2.0 :: Assigning Functions Via A Loop?

Jun 21, 2004

I am working on a page where three differnt buttons effect one movie clips properties, the one movie clip will go to its rollover state when any of the buttons are on rollover,i have assigned functions within a loop and the rollovers, rollouts and instance in the loop have been defined for all but the movieClips dont go to the right place....the code i have used is this....

Code:
for (var i:Number = 1; i < 4; i++) {
// attaching ALL rollovers to effect the interactive button
this["invis"+i+"_btn"].onRollOver = this["chart"+i+"_btn"].onRollOver = this["inter"+i+"_mc"].onRollOver = function() {

[code].....

all the traces show up correct but not the gotoAndStop on the movieClip (inter+i+_mc_)'s.

View 3 Replies

ActionScript 1/2 :: Creating A Movieclip That Functions Like A Button

Aug 16, 2010

This has served me well, but I've been designing a new sight and wanted to get more into Action Script to control functions to help improve both my programming and keep my file size down.
 
So I decided to create an instance of a block (rectangle shape as another movieclip) and have multiple layers.  One which controls the actions of two other blocks.  The upper most block would not be visable until I ran the cursor over it (increase its Alpha property from 0 to 100 one step at a time in a loop).  This would reverse when the cursor ran off (reduce Alpha property from 100 [or less] back to 0 in a loop).
 
I've read and re-read every flash book I own on the subject and cannot understand why I can't control another instance of a different movieclip.

View 1 Replies

ActionScript 2.0 :: Creating MovieClips Through Functions With Arguments?

Sep 17, 2009

I have the following code, which should display some square clickable clips over a map. This is done by calling a function (shown below) with arguments. However, when I call this function, only the last box is shown... The clips are drawn on the same level (9000) but that should not be a problem as they wont overlay...functions calls....

ActionScript Code:
clipsideD=150;
city="Rome"
cityText=romeText

[code]....

View 1 Replies

ActionScript 2.0 :: Creating Functions At Runtime Without So Many Ifs/elses?

Nov 3, 2005

I am writing some code that needs to be very efficient, yet flexible. This is in a class and when the class gets initialized a function is setup. I want this function to run straight through without doing any time-consuming things such as calling other functions or routines, or doing any if/else logic/branching. Now I know that you can setup a function at anytime during runtime such as:

Code:
var myFunction:Function = function() {trace('HELLO!')}

But what I am trying to do is to try and append code to a function based on logic, yet I don't want the function to be deciding this logic when it is running as it will only need deciding when the function is created.... imagine if it were a string it would be something like myFunction+="do somethingelse;" which would be the same as having initially setup myFunction as such:

Code:
var myFunction = function() {do something; do somethingelse;}

With this I seem to be having no luck Here's an example where I setup the most compact/efficient function at runtime depending on what I want the function to do. Now this was fairly simple because when we create the function there are only a few possible variations, but I need someway of doing a function+= as my real code has quite a few variations and it would be a nightmare have a zillion if/else branches. REMEMBER I do not want any logic/decisions in the function itself as it to be the most efficient the function must be as compact as possible and run straight-through.

Code:
var dynamicFunction:Function;
//
// Setup the dynamic function & call it
// In this example outputs "Hello Jim" & "Goodbye Jim"
dynamicFunction = CrapSetupRoutine(true, true, "Jim");

[code]....

P.S. I knew the += would never work as this is a function and not a string. But at least if you think of the function as a string you'll get what I'm trying to do....

View 3 Replies

ActionScript 2.0 :: Creating Functions And Their Contents Dynamicly?

Aug 12, 2008

I have a lot of countries, and i want to make functions for each country, here's working code.

united_kingdom.onRollOver = function() {
animateCountry("united_kingdom")
}

[code]......

View 6 Replies

ActionScript 3.0 :: Casting Variables Into Functions?

Feb 5, 2009

haven't wrote here for a while!This is what I'm trying to do:

var level:Number = 1;
var goat:* = "thisIsLevel" + (level + 1);
var camel:Function = goat;

[code].....

View 3 Replies

ActionScript 3.0 :: Simplify Functions An Variables?

May 26, 2009

I have an animation that has roll overs controlled by AS (see code below). It works the way I have the code, but it's really messy code. And I hate that I'm have the functions rewritten for each event.How can I simplify this code?

//On the main timeline
var gearsEnabled:Boolean = true;
var gears2Enabled:Boolean = true;

[code]....

View 4 Replies

ActionScript 3.0 :: How To Pass Variables In Functions

Jul 19, 2009

I know PHP, JavaScript and AJAX. All of these other languages easily allow me to pass variables through a function, but I can't seem to work out how to do it in ActionScript 3. As you can see from the code below, I have created a variable called 'flag', this variable is set to 'notAdded'. However, once the function is called, I want to change the variable to 'added'. This for some reason does not work, the variable update only works within the function itself. There seems to be no global scope for functions.

Code:
var flag:String = "notAdded";
bobRunning.addEventListener(MouseEvent.MOUSE_UP , bobRunningUp);
if (flag=="notAdded"){function bobRunningUp(event:MouseEvent):void{ bobRunning.width = 30;
bobRunning.height = 30;
flag = "added";
}}trace(flag);

View 5 Replies

Actionscript 3 :: Functions And Accessing Variables?

Jul 14, 2010

I'm trying to create a JW player plugin, a part of the source code is shown below:

public function initPlugin(player:IPlayer, config:PluginConfig):void {
api = player;
var streamUrl:String = 'xxx';

[code].....

View 1 Replies

ActionScript 2.0 :: Performing Functions With Variables

Jan 12, 2010

i've just written the function below and I want to perform it multiple times but with different urls,

[Code]...

View 7 Replies

ActionScript 2.0 :: Class Variables In On Functions?

Nov 30, 2006

I was wondering if they found a better way of allowing the use of variables outside of an on function. For example in the script below I can use the variable bounds inside the target.onEnterFrame function because it's declared inside the constructor. However I can't use m_Bounds even though it's declared in the class.[code]...

View 7 Replies

ActionScript 2.0 :: Paths Functions And Variables

Aug 13, 2007

I have a variable in the _root called 'ordered'. I have another variable called 'total' inside a function called 'loadXML'. 'total' receives a number value from a node in a XML file correctly. I now want to transfer this value to the variable 'ordered' which, as I said, is in the _root. However, 'total' is restricted to the function and I can't access it from the variable in the _root. Neither can I transfer the value from the variable in function to the _root.ordered, since such a line targets the _root of the function itself.I guess this isn't too hard to solve, probably just a path issue, but I have a few rather large gaps in my knowledge of actionscripting.On the stage, there are three objects; a movieclip with the instance name 'clip', a movieclip with the instance name 'orderbox' and finally a dynamic text field with the instance name 'pos_txt'.[code]

View 2 Replies

ActionScript 2.0 :: Passing Variables Between Functions?

Oct 16, 2007

I am building a flash photo gallery that is fed by an XML file, now I am fine with all of the XML things in flash, my problem comes when creating the thumbnail images onRelease event. Here is my code:

Code:
_global.counter = 0;
for (_global.counter = 0; _global.counter<itemArray.length; _global.counter++) {
//populate thumbnail array with URLS

[code]....

The problem is that when I release the mouse button I get a variable undefined error in the output window. I have researched and have found that my problem is that I can't pass a variable from the main function to the onRelease function.

View 3 Replies







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