ActionScript 3.0 :: Create A Global Variable From Inside Function?

Oct 11, 2011

I have a primary function that calls upon other functions, which call upon other functions, etc, each one creating different objects. I need to delete everything eventually and was thinking the easiest way to do this would be to have a global array to push() each object into. It would be easy to just put garbageArray.push(thisCreatedObject); into the for() loops of every function to grab all the objects so a deleteFunction() could just cycle through garbageArray to remove and null everything cleanly.

What I want to do:I could easily just create a global array to do this (code example 1), but I would prefer to be able to recreate this global array and delete it every time this primary function is called (code example 3) since it will be called upon a lot. It would be cleaner code to have it created from within the function as opposed to outside of it because I will have a lot of primary functions doing similar things that would require a global array like this.

I also know I could create one and simply pass it as an argument to every function (code example 2), but I would have to pass it to every single function. There are a lot of functions and a lot of calls to them, so this would require rewriting a lot of code and would be more work than it's worth. Making a global array outside of the function would be easier than doing this if it came down to it.

ActionScript Code:
//example 1 of global array. No passing as argument from
//primary to secondary functions. Multiple global arrays
//required for multiple primary functions in the future.

[code].....

View 6 Replies


Similar Posts:


Flex :: Increment A Global Variable Inside A Function?

Oct 31, 2010

The variable currentIndex is declared globally and initialized with a certain value say '0'. How do I hold the value of currentIndex which is incremented every time the function is called? In the given code, every time the function is called, the value is reinitialized.

function nextSong(e:Event):void
{
sc.stop();

[code]........

View 2 Replies

Actionscript 3 :: Assign Global Variables Inside Function?

Sep 11, 2011

I have an AS3 function that runs when a URLRequest fails. I need to be able to use this function to assign global variables that I can then check against using other functions. How do I assign global variables inside of a function?

Edit:This is the variable (soundFile2Exist) I am trying to get outside of my function:

function onIOError(e:IOErrorEvent):void
{
var soundFile2exist = null;[code]...............

View 2 Replies

ActionScript 3.0 :: Global Variable Within Function?

Aug 24, 2009

I'm having an issue with a global variable. I'm trying to give it a value within a function and it isn't working.The variable is imageList. It's an XML List. I'm making it global so I can use it anywhere in my project. I suppose if someone has a better idea to avoid the global variable, I'm up for that too. But for now, it seems like the way to go.
 
Here's my .as file:
package
{
public class MyGlobal
{

[code]....
 
It's giving me the same same Error #1009 as above. It seems like a scope problem, but why? Shouldn't it work since it's a global variable?

View 6 Replies

ActionScript 3.0 :: Modify A Global Variable Within A Function?

Sep 24, 2009

I've currently got this script (see below). What I'm trying to do is make it so I can load several images from a loop. I've played with a few different things, but I'm not completely understanding how the listener works as it relates to the loader. It seems when I try and add a second image, it only enters the onComplete function 1 time, therefor i only get one Image loaded. As a side note, I've also been trying to dynamically change the x and y position, but I'm not sure how to modify a global variable from within that function, or better yet, pass in the arguements during the eventListener call to onComplete.[code].....

View 2 Replies

ActionScript 3.0 :: Accessing A Global Variable In A Function

Jan 9, 2012

I have a global var

[Code]...

The only problem is it can't "see" myGlobals. I was wondering if someone could tell me why it can't see it! I'm sure it has something to do with scope.

View 3 Replies

ActionScript 2.0 :: Passing A Variable To Global Function In Another Mc?

Sep 17, 2009

After having recently just discovered the delights of actionscript, I am at a loss to work this out. I'll explain:I have a series of buttons which, when each one is clicked, need to grab their instance name (this._name), strip the first three characters from it and send it to a global function in another mc within the swf.Instead of stripping the characters, I am happy to do:

if (this._name == dot1) {
dotVar = 1;
} else {

[code].....

View 1 Replies

ActionScript 2.0 :: Create A Global Variable That Initially Stores A 0?

Oct 21, 2004

I'm trying to create a global variable that initially stores a 0. Then via a function will change the value of that global variable, and allow the other functions to access the new number. I have it working where it adds 1 to the variable, and stores the number 1 however, I cannot get the number to add up beyond 1.

I have this in my first layer,frame.

_global.thisSound = 0;
function PlaySound(){
temp = _global.thisSound;
_global.thisSound = eval(temp) + 1;
}

Please note this is the basics of this function, there are other parts to the function for playing sounds, but this is the only part that I'm having the problem

View 1 Replies

ActionScript 3.0 :: Global Variable Not Accessible From Nested Function?

May 13, 2009

i need to assign a value to a global variable from within a nested function, but my code's not working, any clues? this is within a class definition:
 
// begin code
var numGlobalNumber:Number;
outerFunction();

[code]...
 
i want the text within the dynamic text field to be "1" but it comes up "NaN"

View 4 Replies

ActionScript 2.0 :: Global Variable - Enable / Disable Function Within Game

Oct 23, 2004

I have a button that I would like to enable and disable a function within my game. The button is called "flashBang". I'm thinking this may need to be done with global variables to make the switch do this procedure. How would I go about scripting this variable? Also I want to be able to target this function during gameplay, if this function is enabled do this line of code - _root.gotoAndPlay("flash");

The code needs to fit somewhere in here i guess.
//hitTest top + bottom wall
if (_root.ball.hitTest(_root.topwall) or _root.ball.hitTest(
_root.bottomwall)) {
_root.yspeed = -_root.yspeed;
_root.audio.gotoAndPlay("flash_bang");

View 3 Replies

ActionScript 3.0 :: Sloppy Global Function By Calling Global Function Class

May 14, 2009

I'm try to calling my sloppy global function by calling my global function class as u can see below.[code]

View 2 Replies

Flex :: Incrementing A Global Variable In A Function Which Is Called Multiple Times?

Oct 31, 2010

I am trying to make a simple mp3 player using flash. The songs are loaded using an XML file which contains the song list. The following code is inserted into a new keyframe.

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.*;
import flash.events.MouseEvent;

[code]...

The problem over here is in the nextSong() function. I am unable to preserve the value of currentIndex. Although I am incrementing currentIndex every time the function is called, but the value remains unchanged.

View 1 Replies

Actionscript 3.0 :: Create A Global Function And Static Metod In Another Class File

Mar 3, 2009

i want to create a global function in actionscript 3.0 i can do this in flash as2 As3 remove that _global. if i want to create a _global function then want to create a static metod in another class file...?

[Code]....

View 1 Replies

ActionScript 2.0 :: Passing Variable To Function Inside Function?

Sep 16, 2009

I need to pass a variable to a function inside a function. However this parameter (i) seems not to be passed (to function ...onRollOver). This is required to attach a textfield to a movieclip (reading the adress and showing it as a tooltip).

ActionScript Code:
for (i=0; i<array_BE_ElecCities.length; i++) {
var attachElecCity = mc_map.mc_places.attachMovie("Plant",

[code].....

View 1 Replies

ActionScript 3.0 :: Declaring A Variable Inside A Function To Use Outside The Function?

May 5, 2011

I want to create a vector, then call a function that populates that vector with arrays. Fine. The only catch is the function itself will declare new array variables to put into the vector, but are these new array variables private to the function only?e.g. something like this

ActionScript Code:
public var vec:Vector.<Array> = new Vector.<Array>();
private function populateVec():void {

[code]....

Is this "kosher"? a was declared in the private function but added to something outside the function..?

View 4 Replies

ActionScript 3.0 :: Global Variable Event - Create An Event Detected To See If It Reaches A Certain Number?

Oct 26, 2010

If I have a Global Variable Globalvars.vars.noLoaded which is in many classes How do I create an event where i detect to see if it reaches a certain number.
 
[code]...

View 3 Replies

ActionScript 2.0 :: Create An Input Text Box That Puts The Users Input Into A Global Variable?

Apr 12, 2007

i created an input text box that puts the users input into a global variable, but when i test it it gives me not only what i have typed in but all the html formatting for the font that my input text box has on it.I only want the text that i have typed in to go into the variable but the wackload of html is going in there too. ive tried a few different things, rewriting my code, recreating the text box, changing settings, dont know what im missing.

View 10 Replies

ActionScript 2.0 :: CS3 Global Variable Not Being Global

Jul 22, 2009

i defined the global variable in the first frame of my file, and i can access it on other frames, however i am trying to access it within a movieclip, and flash is telling me that it is undefined. does anyone know why this could be?

View 1 Replies

ActionScript 2.0 :: Load A Variable From The .fla Inside A Function?

Jun 2, 2011

I have some buttons in the scene (inside the .fla) that change a variable "counter" after being clicked. In a separate class there is a function "showPage" that loads a xml-file according to the value of the variable "counter". My problem is, that I dont get the variable "counter" from the fla-file into the function of the .as-class.

Here is my code:

Inside mcMain.as

Code:
class mcMain extends MovieClip
{
//public var counter:Number = 1; //Das hier soll durch den Button getan werden :(

[code]....

View 1 Replies

ActionScript 3.0 :: Getting Variable Value From Inside Of Event Function

Feb 29, 2012

How to get variable value from inside event function. Variable was declared outside event function.
var StringVar="sample";
myButton.addEventListener(MouseEvent.CLICK, myClickReaction);
function myClickReaction (e:MouseEvent):void{
StringVar="other sample";
} trace(StringVar); /*

It gives me "sample" value and I would get "other sample" value */. That strange because if that would be normal function trace would give me good result.
var StringVar="sample";
function myClickReaction():void{
StringVar="other sample";
} myClickReaction();
trace(StringVar); /* it gives me result as I wanted to have - "other sample" value */

I know also method of passing arguments into event fuction but it not works for me as I would like to
var StringVar="sample";
myButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){ myClickReaction(e, StringVar) },false, 0, true);
function myClickReaction (e:MouseEvent, StrVar:String):void{
StrVar="other sample";
} trace(StringVar); /* it also gives me "sample" value and I would get "other sample" value */
How to do that correctly?

View 11 Replies

Flash :: Call Variable Inside A Function ?

Sep 25, 2011

I'm trying to pass a variable through a function, but I'm getting it's value 0. Here's my code:

thumbLoader.addEventListener(MouseEvent.CLICK, goToCategory);
function goToCategory(e:MouseEvent) {
trace(c);[code]....

this trace gives me value of 0. Normally I would do goToCategory(c) and inside that category I would get it's value, but in this case I'm calling this function with an event, how can that be done?

var c is declared globally, so I'm using it above this code in different place... is there smth like global $c like in PHP.. or there's some other way to do it?!

View 2 Replies

ActionScript 3.0 :: Access A Variable From Inside A Function?

Dec 8, 2009

i am trying to access a variable from inside a function like this:

ActionScript Code:
var X:Number=1;
function hello(event:event){
trace(X)
}

or something like that... does anyone know why i don't get "1" in the output panel when i run the code?

View 3 Replies

ActionScript 3.0 :: Changing Variable From Inside Of Function?

Jan 9, 2010

I have a code, it is below. And i have two vars: coordx and coordy they both are 0 but when up button is pressed, coordx should change into 1 x remain 0 just like map scrolling and if pressed down it should return to default position, but instead of that variables keeps reseting and it starts from beggining. Here is the code:

ActionScript Code:
var coordx:Number = 0;
var coordy:Number = 0;[code].......

View 3 Replies

ActionScript 3.0 :: Change Variable Inside A Function?

Oct 19, 2010

How can you change a variabele in as3 that you have declared OUTSIDE a function and change it inside the function.My function seems not be able to change the variabele?

ActionScript Code:
function Filter2switch(event:MouseEvent) {
if(filter2 == false){

[code]......

View 1 Replies

ActionScript 2.0 :: Variable To Be Available Inside The OnLoadInit Function?

May 20, 2007

How do I get the for-loop's i variable to be available inside the onLoadInit function????

Code:
for (var i = 0; i<nTotalPics; i++) {
main.createEmptyMovieClip("container"+i,i);
var container:MovieClip = main["container"+i];[code]....

This has been bugging me for about 2 months now. Maybe I'm looking at it the wrong way, but I need to create more things in the onLoadInit function using a for-loop.

View 5 Replies

ActionScript 3.0 :: Use Data In Variable Inside Function In Ouside?

Jul 22, 2009

how can i use data in variable inside function in ouside

var m:Number=0;
function bClick(e:MouseEvent):void
{

[code]....

when i trcae (m); out side this function said 0

View 1 Replies

ActionScript 3.0 :: Memory Leaks - Variable Reference Inside A Function Or Outside It?

Mar 11, 2009

I wonder what the most common reasons for memory leaks in AS3 are.First thing what I am not sure about is: is it better to have a variable reference inside a function or outside it. Will the variable be null-d automaticly inside a function or when do I have to null it and when not?I have massive problems with my game with memory leaks. I noticed I reference some of the clips of the timeline even inside my debugging clip to display propertys and this was causing collecting huge amount of memory.But even before I go into the game with bigger objects the System.memory is slowly growing and growing.I just have a socket connection and some interval loops and enter_frame events.

View 5 Replies

ActionScript 3.0 :: Convert The Watch Function - Cannot Use This Variable Inside Any Other Class

May 20, 2010

I have been trying to convert the watch function code into AS 3. I am totally new to AS 3 and could not find the solution yet. Here is my code -

[Code]...

The variable 'buttons' must be in the root timeline. And, I cannot use this variable inside any other class.

View 2 Replies

Flash :: Create A Variable In Flex-config Xml File Usable Inside Of It?

Mar 29, 2011

We can auto-generate flex-confix xml file from flash-builder so to provide users that want to compile project on there own would be capable of doing such thing with out buying FB. So we use something like -dump-config slotConfig.xml as flex compiler argment. This generates a file for us... with lots of detailed comments like this one I generated from that project:

<flex-config>
<!-- benchmark: output performance benchmark-->
<!-- benchmark usage:

[Code]....

View 1 Replies

Flex :: External SWF Variable Updates Global Variable In Main Timeline?

Feb 8, 2010

I have 2 movie clips, one being loaded into a container MC via "loadMovie();"In the main movie there is a variable with no value, in the external movie there are 5 frames, each with a value to update the variable in the main movie.

IE: if on frame 1, global value = 1 / if on frame 2, global value = 2 / etc etc I'm familiar with passing variables INTO an external swf, but am stumped on how to do it the reverse way.

View 1 Replies







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