var q4:Boolean = false; //Will have thirty-eight of these, q4-q41
function noRepeat() {
if (q(_root._currentframe) == true) {
gotoAndStop(randRange(4, 41));
} else if ((q(_root._currentframe)) == false) {
q(_root._currentframe) = true;
}
}
Now, my problem is the bits in red (yes, I know they don't work, that was just the best way I could think to describe what I wanted).
If I create a string that says "q4" then I find it won't compare that to the boolean variable, but I'm positive there must be a better way than putting one of these on every frame.
So, performance wise, is it necessary to null references to classes, etc inside a function? Something like: Code: function myFunction():void{ var myVar:myClass = new myClass(); //do stuff with myVar... //don't need myVar anymore myVar = null; //is this necessary? }
I'm working with 2 global variables and I need to compare them on 6 different button function clicks for a lot of different scenarios.[code]My function is starting to look like this;[code]only problem i see is that there are many different scenarios and this if statement could get very long. Is there a way to combine it somehow so there wouldn't be that many else if's?
For login I need to compare two variables. One of the variables (passw) is loaded dynamically. The other one (pw) is set by a form the user hast to fill. I wrote the following code on a button in the frame where the user hast to type his password (passw is already loaded from a textfile):
on (release) { if (pw == passw) { gotoAndStop(4); } else { gotoAndStop(3); }}
In frame 3 I wrote: "wrong password", code is stop () In frame 4: "welcome user", code is stop() I tried half an hour to fix that but I always get "wrong password". One more question: is a movie loaded with loadMovie(...) able to work with variables set in the main movie (in which I loaded it)?
I've got an xml file that contains some data (which will be created by an external file later on in the project) and i want to be able to check the data in that XML file against a variable stored in flash.
If the value in the XML is equal to or greater than the value in the variable i want to jump to a different frame. If the xml value is less that the variable value i want it to stop and tell the user a message. i've included my code below. I just cant get it to work. Regardless of if the value in the XML file is higer or lower than the variable in flash, it always continues to the final frame instead of stopping accordingly.
ActionScript
Code: //Load xml file that contains amount of cash user has and populate cash_txt box with amount function loadXML(loaded) {
I am making a scoreboard. On this scoreboard I will have 10 different scores. I want to compare the 10 scores and list the top 3 scores in another location. I was thinking at first if(score1>score2&&score1>score3&&score1>score4 etc.....){ some function } But this will only give me the top score in the group. I would like to find the top 3 scores, and then list them.
Functions embedded inside other functions? In all my years of ActionScript programming, I've never seen this (this is part of legacy code written by someone else which I am adapting):
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.
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?
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.
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?
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;
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);
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]...
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]
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.
how to access variables that are declared in a movie clip from a function declared in that same movie clip.
i.e. **************************** var int1 = 1 var int2 = 2
[Code]....
I'm trying to do this in the main movie clip of a movie that I plan on importing dynamically in another movie. I've tried to use this.int1++, but I think that flash was looking for a variable that belongs to "myfunction" when I did that. I could just use _root.int1++ but like I said, I plan on dynamically loading this into another movie, in which case it would be pointing to the wrong movie.
ActionScript Code: //links var navBarButtonArray:Array = new Array(navBar_mc.gadgetNews_btn, navBar_mc.gadgetReviews_btn, navBar_mc.gadgetFeatures_btn, navBar_mc.iphoneNews_btn, navBar_mc.androidNews_btn); var categoryArray:Array = new Array("news", "reviews", "features", "iphone news", "android news"); var navBarLinkArray:Array = new Array("http://feeds.feedburner.com/T3/news.rss",
Code:stage.addEventListener(KeyboardEvent.KEY_UP, reloader); function reloader(e:KeyboardEvent):void {[code].....
and this:
Code: var reloadT:Timer = new Timer(2000, 2); reloadT.addEventListener(TimerEvent.TIMER, on_timer); reloadT.start();[code].........
So I have a code that tracks Key_UP and one for a timer. However, I want to somehow use them together, like inside each other: ex. Run the timer function in Key_UP.I want to trigger the timer only if Key_UP is found. How would I do this?
I'm working on a project for school which is requiring me to make a game using Flash and ActionScript 3.0. One of the tasks I have to do is load an external XML file that will be displaying questions and answers. I've looked at google to find simple scripts for loading XML, one example being below:
Code: var myXML:XML; var myLoader:URLLoader = new URLLoader();
I was wondering if ActionScript had some way to call functions and classes from variables, like they do in PHP:
function funcname() { print "Potatoes come from tree"; } $function = "funcname"; print $function; // Prints out "funcname" $$function(); // Prints out "Potatoes come from tree"
In case you don't know the syntax for PHP, you should know that anything perpended with a $-symbol is a variable.