ActionScript 3.0 :: Declaring Variables Inside Function And Use Outside?
Feb 25, 2010
I know that as long as a I declare variables inside a function I can only call them as long as the scope of the function is active. Outside of that function the variables don't exist. Is there any way I can create those variables inside a function and use them outside of it?
View 1 Replies
Similar Posts:
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
Mar 21, 2012
I have an empty SWF that's sole purpose is to call loadMovieNum and start the project. Each loaded movie has a few variables defined within them - unique to those loaded SWFs. Instead of declaring all the variables in each SWF can I declare all of them in one place, in the first frame of the empty loader it all starts from? I'm thinking I can then declare a variable which each loaded movie can increment as needed for me.
View 2 Replies
Feb 25, 2011
I found this in an ActionScript class in flex.
protected::valueMin know what this exactly means. at the outset, I dont see any type declaration. I am a newbie in flex.
View 2 Replies
Dec 27, 2009
I have a simple math game where the user enters his answer and clicks a button. The problem I am having is that if the answer is wrong, the numbers in the question do not change on the screen but but in the actionscript, the variables being used to check the answer change. How do I get the variables to stay the same when the user's answer is wrong? Not redeclare all of the variables.
Code:
var num1:uint = Math.Random()*1000;
var num2:uint = Math.Random()*1000;
var sum1:uint = num1 + num2;
[Code].....
View 1 Replies
Nov 27, 2009
I have a set of Cue Points in an FLV I'm playing. It's an interactive quiz, so the idea is that flash will change a variable, theAnswer, to a different letter depending on which question it is. The answer to question 1 is B, question 2 is D, etc. Either the cue point event listener isn't working, or else it is working and Flash isn't declaring the variables. 1120: Access of undefined property theAnswer. I literally can't find a single problem with my code. I have an almost identical Event Listener further down which works.
[Code]...
View 4 Replies
Jul 27, 2009
is it possible to declare function this way
ActionScript Code:
function startShake(e:MouseEvent, num1, num2):void
what i mean is it possible to send to the function not only en event but also a variable and a second question how can i access
ActionScript Code:
function stopShake(e:MouseEvent):Array
this array that function return.
View 1 Replies
Sep 20, 2003
I'm pretty new to AS, I understand that whatever variables you have inside a function will be discarded once the function finishes? I need the value of a variable that's inside a function, I've tried declaring it outside the function, and also give it an initial value, but it seems that when the function finishes the variable goes back to it's original value.
View 5 Replies
Dec 21, 2011
I want to declare on multiple numerated variables like this:
var myVar1;
var myVar2;
But I don't want to do this manually for every variable instance but automatically, so I need a way to instruct the compiler to declare by himself on every variable and to numerate them automatically.
So hopefully I explained myself well, I wanted to know if there is such way to do this?
View 2 Replies
Sep 17, 2007
I was wondering what the rules are for declaring variables which you would increment say in an for loop. I tried to declare a variable outside the for loop, and then increment it within the loop but that didn't work.
View 2 Replies
Nov 21, 2010
I want to declare 8 variables at the class level like this:
Code:
private var graphicDesign1:Sprite;
private var graphicDesign2:Sprite;
private var graphicDesign3:Sprite;
private var graphicDesign4:Sprite;
[code]....
But I would like to do it with a for loop. Is that possible? If so i'm doing it wrong this is what I have.
Code:
for(var i = 1; i < 9; i++){
private var +"graphicDesign"+i:Sprite;
}
View 1 Replies
Oct 10, 2009
does anyone know if declaring new variables within a switch statement (inside of case: break actually creates new variables inside those switch statements, or are the variable declarations moved to the top of the function when compiled?
i know that when declaring new variables inside a for or while loop, the compiler declares those variables at the beginning of the function. is it the same for if or switch statements?
View 3 Replies
May 27, 2002
i am wondering where and how i can insert global variables in my code (below)....or is that too 'C' a concept!?!...see what i am trying to do here is this...onClipEvent calls within it attachMovie from my library with the appropriate linkages...a few setProperty here and there...what i want is a few characters initialised above the rest of the code...why?...coz as u will see, when k=0, a movie is picked up, put at level m=1...
...the second time round the loop begins, k=1 so a movie gets picked up again at random...now this is where i need ur help...the second (and subsequent 3 movies) need to be placed on top of the basemovie...i am trying swapdepths here...good hoice?...anything else i can do?...yet to figure out reducing the opacity of subsequent movies...see i am looking for a motion trail kinda effect...so at one point of time 5 mc will be visible...total no. of mc=250 and at random they get picked up over and over again...
[Code]....
View 8 Replies
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
Aug 17, 2010
I have attached the actionscript file on stage, however I can't access function or variables inside movieclip. Instead I can access them on main timeline, is there a way to access function and variables inside movieclip
View 2 Replies
Apr 30, 2011
I am writing a program that requires the use of 36 boolean variables with different names (e.g. box1, box2...): does anyone know of a quick way to optimize this program.
View 5 Replies
Oct 26, 2009
I'm trying to declare arrays inside a for loop, then access them later as if they were declared publicly/globally. This doesn't work:
Code:
playlist = addChild(new MovieClip());
playlist.header = new Array();
for (i=0; i<3; i++) {
playlist.header[i] = playlist.addChild(new MovieClip());
or (j=0; j<6; j++) {
[Code] .....
How would I declare the arrays within the for loop, but still access them later without them becoming undefined?
View 2 Replies
Jul 25, 2009
why can't i get a return value from this function because i need those values to reset a image to it's previous position.
PHP Code:
Cam.addEventListener(MouseEvent.ROLL_OVER,animIn);
trace(animIn); // here is where i got a problrm
function animIn(evtObj:MouseEvent):Array {[code].......
why i can't do it like that what i mean is why i can't declare this function that way because when i do the fallowing error occur:Ereor #1063
View 5 Replies
Sep 2, 2009
I wanted to use a couple of stand-alone function/or static methods by declaring them in the external *.as file and import it.
The problem is, when I import it, I had to instantiate a new class from imported class to use any of these functions which is not necessary in my situation, I just wanted to be able call these functions.
It (AS) does not allow me to declare those functions outside of class declaration, (tried with static keyword in front of those functions just like in C++).
I also tried to declare the class itself with static keyword (also just like C++) but AS also does not allow me to do that.
Remember whole points is declare couple of helper functions in external *.as file and use it over and over.
View 5 Replies
Mar 18, 2009
I'm trying to create a unique variable and reference to it with myRewind for some button functions.
I'm trying to create this rewind+variable as the unique identifier but it just seems to be using myRewind as the variable and overwriting it.
Code:
//Setup subsection rollovers
function createRollover(myContainer, rollName) {
btnName = rollName+"_btn";
mcName = rollName+"_mc";
[Code]....
View 2 Replies
Jul 30, 2009
I am trying to send a value from one of my xml nodes (<marker>) by declaring it in a function 'showData' as a variable 'XMLMarker'. If I trace this value (XMLmarker) it returns the right data found in the node <marker> (which is 'myMarker_mc'). However, I need to tell the stage that myMarker_mc is a MovieClip...please see the 'PROBLEM' stated in the code below.
[Code]....
View 0 Replies
Jan 14, 2010
In the code below i want to change the _root.broj and _root.logo variables inside the function which returns values from .php file. Inside the function everything works fine and all values are correct but when i trace var broj outside the function it's still 0.
var result_lv:LoadVars = new LoadVars();
var send_lv:LoadVars = new LoadVars();
var broj:Number=0;
var logo = new Array();
[Code].....
View 1 Replies
Sep 20, 2009
I am creating a Weapon class for a game and the weapons itself will be the sub classes. The sub classes will hard code some values (such as max ammo and the weapon name).
I trying to access this declared data in the base class constructor, at the moment it's not outputting the values. Is this possible?
I've broken my Weapon class for simplicity:
ActionScript Code:
package
{
import flash.display.MovieClip;
[Code]....
My current workaround is creating a protected method in the base class to trace the information and calling that method in the sub class's constructor, this works fine but this doesn't seem like the most efficient technique?
View 7 Replies
Feb 22, 2011
I have an object which is assigned a number of properties:
var project_array:Array = [];
var slideObject:Object = {
project_title : myXML.projects.project[i].title.toUpperCase(),
[Code].....
but I'm not quite sure where to place this. If I place it outside of the object constructor, I get "term is undefined", I guess because it doesn't know what project_clips_array is - but if I declare project_clips_array in the constructor, it appears to need to be defined, i.e. I can't create a blank property. But I can't place it in the constructor either, because it doesn't seem to allow me to run a function within an object constructor. What is the proper syntax or arrangement of code for executing this function to get the array within the object?
View 2 Replies
Dec 8, 2009
I have done this same thing in ActionScript 3, but am not familiar with ActionScript 2, which I am forced to use for this project. I am loading products into a SWF via XML and attempting to add a click event to each dynamically-created movieclip. Simply tracing the text from a node in XML will do for now. I'd like to assign a property called "desc" or "description" to each movieclip and have it trace that property's value when clicked. Here is the relevant portion of my code as it stands:
ActionScript Code:
var iXML:XML = new XML();
iXML.ignoreWhite = true;
[Code].....
View 6 Replies
Feb 12, 2011
var speed:int = 4;
addEventListener(Event.ENTER_FRAME,MoveRight);
function MoveRight(event:Event):void{
[code]......
View 3 Replies
Sep 23, 2011
I have an AS3 function that loads and audio file and then plays it. I have the pre-loader for the first audio file working - now I need to run the pre-load function before the 2nd audio file starts.
myMusic.addEventListener(ProgressEvent.PROGRESS, onLoadProgress2, false,0, true);
myMusic.addEventListener(Event.COMPLETE, playMusicNow, false, 0,true);
myMusic.load(soundFile, myContext); //This code works
[code].....
View 2 Replies
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
Sep 28, 2010
in this case this.name return me root1
i was expecting the name of the function caller witch is a btn dynamicly created on stage (see exemple)
var facebook:SimpleButton = new socialIconFacebook();
addChild(facebook);
facebook.x = 134;
[Code]....
i know i could put the url right there instead but i have a lot of btn who would use that function
View 5 Replies
Dec 8, 2009
function test1():void
{
function test2():void {..}
[code].....
View 6 Replies