ActionScript 3.0 :: Array Variables, Variables Not Working Correctly?
Jul 11, 2011
There is a bird, and you control its upwards movement with a key. It has thrust, gravity, it works fine. The problem is I have a bunch of icicles that come at the bird that he is supposed to avoid. I tried this first with math random to use as an x coordinate and than move across the screen, but the icicles had the same x-coordinates sometimes. I tried does not equal(!=) but that doesn't work. I made an array and each number that came out of the array I assigned a different variable. This works fine. I put this variable into the x-coordinate such as mc.x=((n)*60)+480. I did this for five different icicles. All their differnt variables have a different value, and I put them into the same function for each individual video clip, but they still don't go to the right coordinate. Here is the test code just for the initial coordinate of each icicle before it moves...////////////////////////////Quote:
var temp:Array = new Array()
for (var i:int=0;i<8;i++) {
temp.push(i);
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.
I have a list of strings that I add to an array, then attempt to set those values in a for-loop using data that I read in. The array gets updated, but the values the array contains do not. I also have an array of buttons that I update this same way that works great, but strings don't seem to work the same way. I have tried moving the string array to give it full scope, and still nothing...
public class test extends Sprite { // Declare a list of strings protected var title0:String = undefined;
I have some variables created on the main timeline and a mc called options which will be where those variables can be manipulated. A way I've tried to this is by creating a first array(array1) and populating it will all the variable names found on the main timeline, and another array(array2) containing the values of the variables the user has changed(which are displayed on some dynamic text fields). To make these changes, an "apply" button is pressed which will set the values found in array2 to the variables in array1.[code]How would you do this so that var1, var2... are updated properly according to the values found in array2?And because array2 contains strings(read from dynamic textfields), how do you deal with that since var1 and var2 are numbers?
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.
I'm writing code that takes data from mysql that's processed by a PHP script. It's actually a bit bizarre, at least to me. Anyway, here's some basic AS3 code that's moving toward what I want to do:
var loader:URLLoader = new URLLoader(); var urlRequest:URLRequest=new URLRequest("receive.php"); urlRequest.method=URLRequestMethod.GET;[code]....
For some reason, the statement "trace(evt.target.data);" produces a whole pile of garbled text before the actual stuff that it's supposed to show Because of problem #1, I've had to include a throwaway variable at the beginning, otherwise the first variable I try to pass into AS3 comes back as undefined. This causes errors when I run my flash movie in the IDE, but when I run it from the browser it doesn't seem to have any effect.But this is the strangest thing of all whenever I make any changes to the database (and subsequently try to load data from different variables), the new variables come back as undefined. For example, let's say that I add another entry to the database, and decide to load students 2, 3, and 4 instead of 1, 2, and 3. When I do that, any new data I've added comes back as undefined, even though when I view the PHP output in my browser, it looks just fine.
And now for the REALLY bizarre part: I'll copy that output, paste it into my PHP script as an echo statement, comment everything else out, and my flash movie runs fine. Even though the output from the PHP script is exactly the same, it gives me errors.
pictures2.php is working cos I just check so by rite the variables loaded should change.. but somehow each time I check those variables in myPictures.onLoad, the variables are always the same.
I had written this code out using Adobe CS3 and have recently upgraded to CS5. I haven't touched this site in forever and the last time that I did it worked great. The problem is as follows.type of page: galleryproblem: passing variablesthis is the original code that worked last time I checked it but has since stopped working.
function onClick(e:MouseEvent):void { trace(e.currentTarget.name);
So I'm trying to get my actionscript code working, and I'm having troubles.I want it so that when I drag a movie clip onto another movie clip it changes a variable to a number. However, there are three possible movie clips to drop onto, and I want a different number for each. I have a movie clip and inside it is a button with code along the lines of:
I'm working on a dating sim (don't ask) and I already figured out most of the variables, but I have one problem. When the experience with one of the characters is a certain ammount, I want to play a different frame of dialouge.
Is there a way to play a new frame, only if the variable equals 10?
I have a project that needs some global variables. While developing on my local machine I made a 'globals.as' file which contains the following: ActionScript Code: package { public class globals { public static var gData:Object = {}; }}
I import that using ActionScript Code: import globals; Then in my code if I need to create or access a global variable I can do something like: ActionScript Code: globals.gData.myNewVariable = "whatever";
This all worked fine until I exported the project to the web, suddenly it's as if globals.gData is not an object anymore. Only thing I can think of is that it's not importing globals.as. Is there a special way I have to embed globals.as into my project?
Code: var positions:Array = new Array(Stage.width / 2, Stage.height / 2);
When the above code is executed, the values "Stage.width / 2" and "Stage.height / 2" are replaced with the number values and the array becomes, for example [500, 400].And when I call the array positions[0], instead of getting the value of the Stage.width / 2 (considering the stage has been resized), I get the static value of 500.What can I do to get the value of Stage.width / 2 ?
Why doesn't AS2 interpret these variable as it steps through? Everything works if I write it out longhand and do not use a loop, but if I try to condense things by using an array, variables such as _root.myTargets[i]._x are not interpreted properly.
Code:
myTargets = new Array('shoot','shoot2'); for (var i:Number=0; i<myTargets.length; i++) { if ((_root._xmouse > (_root.myTargets[i]._x - 30)) and (_root._xmouse < (_root.myTargets[i]._x + 50)) and
I think I am getting pretty close here but can anyone direct me in the right direction to be able to return the values in the array in a sequential order?
Code:
var twentythreeX:Number = 0; var unihiphopX:Number = -320; var unimetalX:Number = -760;
[Code]....
This is for a simple slide show just when the next button is pressed it will tween to those coordinates.
I am trying to load variables from a text file, and have them available from then onwards in the movie, globally so to speak.
While I can read the variable values in a loader function which executes when the text file is loaded, I don't seem to be able to keep those variables available afterwards.
I'm trying to figure out which is more efficient in terms of memory and speed. What I'm doing is having a series of messages loaded to the screen. Is it just faster to write them in string variable or in an XML document which is more versatile in terms of editing and adding on to the document.
iam trying to append 3 variables to a url that already has 2 variables appended .. iam using the LoadVars -> "send" method but it wont work. it works if i use a url like "form.aspx" but it wont work if i use "form.aspx?var=nun" which is what i need so i can append 3 more variables to that URL.
I have this code to push "Variable1" in to MyArray: ActionScript Code: _root.MyArray.push(Variable1); Note: "Variable1" is a number stored as a string. When "Variable1" changes, the code above is called upon to add the new "Variable1" value in to MyArray. Then I have this code which is called upon to find the sum of all the values within "MyArray":
My problem is that rather than adding the values contained within MyArray (as if they were numbers), the values are being concatenated instead.
Example: If MyArray values were 1, 2, 3 I want the MyArray_Total to = 5 But instead... MyArray_Total = 123
I tried making a new variable named "Variable1_num", declaring it as a number, making it equal to "Variable1", and then pushing "Variable1_num" in to "MyArray"... but that didnt seem to work either.
I am doing my first simple game using Flash CS5 and Actionscript 3.0. In this game the player would be able to create a new quiz where it would create an array and add sets of questions and answers to that array. I have been looking on how to do this or anything like it and it doesn't seem to be possible (at least in this way).
I'm interested to fill a simple array with variable names, NOT with strings! , because I need it for catching the data from asp file.I tried something like that but it doesn't work