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
Similar Posts:
May 24, 2010
Making a flash page that can cycle through these three images on mouseclick. For some reason the local changes to count are not reflected on the global one. I tried _global but the syntax was odd and gave me errors.
import flash.events.Event;
var images:Array = ["images/image.jpg", "images/image2.jpg", "images/image3.jpg"];
var count:int = 0;
forward.addEventListener(MouseEvent.CLICK, loadPhoto);
function loadPhoto(evt:Event){
[Code] .....
View 3 Replies
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
Dec 9, 2008
I want to import a new image ever 5 seconds but how can I increment the counter variable from within the function?
PHP Code:
count=0;
function loadimage(count) {
trace(count);
[Code]....
View 1 Replies
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
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 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
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
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
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
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
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
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
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
Aug 19, 2009
I've developed a component which is a combination of a few items (canvas, labels, etc...) but when I try to bind it to a variable such as: {stationXML.getItemAt(1).AAA.@value}, it doesnt work. Before I combined all the items in a component, they were all in the main MXML file at which time they worked. Not sure if it matters, but the "stationXML" arraycollection variable is declared inside the file "Station.as".
View 2 Replies
Apr 7, 2011
I'm trying to make a global eventListener. Everything works fine, the KeyboardEvent.KEY_DOWN fires all the time .. except the cases when the textInput has a focus.Here's how I attach listener:
FlexGlobals.topLevelApplication.systemManager.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, true);I've tried both (use capture and without it).
View 2 Replies
Aug 10, 2011
I am trying to work with a global variable in Flex and it does not appear to be working correctly. In my default mxml file I declare the following
public var appID:int;
This variable keeps track of the session ID across my application for SQL purposes. On another mxml page I call the following code which should update the global variable to the current ID.
// Get the ID
sqlStatement.text =
"SELECT Max(id)FROM applications";
sqlStatement.execute();
var result:SQLResult;
result = sqlStatement.getResult();
FlexGlobals.topLevelApplication.appID = result.data[0];
Lastly I run a SQL Update query using the ID as a parameter. My problem is that the FlexGlobals.topLevelApplication.appID is always 0, for some reason the global variable never gets updated, I have checked to ensure that result.data[0] is correct but the value never gets passed to the global variable.
View 2 Replies
Nov 20, 2011
How do you define a global variable that is accessible across all views on Flex mobile / Flex 4.5/4.6
(Edited for clarification)
Is it still necessary to have to use a separate global class?
(additional) There is a new PersistanceManager in Flex 4.5, is there something like a GlobalObjectsManager that can be used to just set/get stuff in memory?
View 2 Replies
Feb 29, 2012
i have searched the actionscript reference page and can't seem to find how to declare simple global variable.
View 3 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
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
Sep 12, 2009
I have an actionscript Tween that travels from the top of the stage to the bottom.I want to have a variable that displays the Y coordinate. To do this i have tried an if statement and a for loop, but none seem to work.[code]
View 5 Replies
Nov 2, 2009
this is what I have:
[Code]....
In other words, I want the variable to increase by one each iteration of the loop. I'm sure there is a simple solution to this and I am currently banging my head against my desk
View 5 Replies
Aug 29, 2007
what is the proper way to increment a variable with a mouseevent listener?
var myMinVarable:int = myNewMinVariable;
myNewMinVariable = 0;
var myMinDMinVariable:int = 10
[code].....
View 11 Replies
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
Oct 11, 2011
I need a variable to increment a value in each click of the mouse clicks in the end according to the final results.
View 2 Replies
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
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
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
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