ActionScript 3.0 :: Creating Variables Using Set()?
Jan 3, 2009Does the set() function for dynamically creating variables have a substitute in AS3?
This is a generic example written in AS2:
Does the set() function for dynamically creating variables have a substitute in AS3?
This is a generic example written in AS2:
I need to make new sprites on-the-fly within a for loop, and this code does not work:
Code:
for(var i:int = 0; i<5; i++) {
var this['menuBtn'+i] = new Sprite();
[code].....
I was wondering if it would be possible to use a for loop to create a couple hundred variables. I wanted to do this so I wouldn't need to type everything out. Right now it looks like:
Code:
var cardname1:int = 0;
var cardname2:int = 0;
var cardname3:int = 0;
[Code]....
Is there a way to create all of these using a for loop?
using flash to create XML, and most tutorials I find on the subject deal with opening external XML files and parsing them in flash, not using flash to make them.Here's my code:
Code:
function saveSong(e:MouseEvent):void
{
for(var i = 0; i < myStaff.staffArray.length; i++)
[code]....
What I am trying to do is create a <measure> element for each item in my array, and then 8 <line> elements in each measure. I'll populate these <line> elements with data later.
Here's what the trace is giving me:
<song>
<measure>
<line></line>
[code]....
The problem I have is that empty space in the first line of <measure>. How do I prevent this from occurring? I can see I will have the same problem when I go to populate the <line> elements as well.
I'm trying to create a template for a drag and drop question. I want to assign which option belongs to the correct target.Each draggable option is called "drag1, drag2, drag3, etc.". (created on the stage) Each target is called "target1, target2, target3, etc." When a button is clicked, the correct answer is checked using a simple if loop and the user is told which ones are correct.
Code:
if (drag1._y = target1._y) {
//show if correct or incorrect
[code].....
i'm loading several sound files, and want to error check each load. however, instead programming each one with their own complete/error functions, i would like them to all use the same complete/error handler functions.
a successfully loaded sound should create a new sound channel variable, while an unsuccessfully loaded sound will produce a simple trace with the name of the sound that failed to load. however, in order to do this, i need to dynamically create variables, which i haven't yet figured out how to do.
here's my code for my complete and error functions:
function soundLoadedOK(e:Event):void
{
//EX: Sound named "explosion" will create Sound Channel named "explosionChannel"
var String(e.currentTarget.name + "Channel"):SoundChannel = new SoundChannel();
[Code].....
I am trying to place API variables on ONE class file or mxml file and call these variables in other random class or mxml files..
View 1 RepliesI have a function in which I declare a bunch of variables that I need to be globally accessible from outside the function.[code]I need numVals to be accessible from outside the function.I tried changing the name to _global.numVals and it didn't work
View 4 RepliesHow do i create variables in AS3 that have variables in the name.
for example, i have a for statement that goes from 0 to 5 and what i want it to do is create 5 variables called variable0 -> variable5
in AS2 i remember it was either this["variable"+i] or eval("variable"+i) but i could not figure out what it is in AS3.
I've created a basic function that sets a movieclip to a certain state depending on which mouse cursor is set (determined by a variable called txt_cursor). I can hard code this to work great for the one single movie clip but potentially have to do this for 624 other movie clips so obviously want to create a for loop to reproduce this.
Code:
chk1.onRelease = function()
{
[code]........
How can I randomly create some variables as the movie loads so I'll be able to use this variables as a if statement later on and make the movie play diferent labels?
View 4 RepliesSo what I'm trying to do, is allow users to create a bike type game. There are four different parts to it that they can choose (frame, material, tires, and handelbars), each that change one of the four different statistics (weight, durability, speed, and maneuverability) and I'd like it to update these global statistic variables each time a part is changed so that the statistic bars can update.I want to have the bike frame, when selected, to set a base for all 4 variables, and then each other part will add to it. This is what I did so far. . .
on the framescript I just have:
_global.durability = (_global.framedur + _global.materialdur);
_global.weight = (_global.frameweight + _global.materialweight);
[code]....
I have done some (like 2 hours worth) research and have come up short, so while I browse the forums for a bit more help Basically what I'm trying to do is create a number of variables, depending on how many items are in an xml document.For example, I am running a for(){} loop to pull all the data I need out, and I would like to store it in the format:photo1.filename = whatever; photo1.value2 = whatever;
and so on. All the object property names (filename, value2 in the example) would be the same (obviously the values would be different), but I need the number of objects (photo1 in the example) to depend on how many nodes are in the xml document.
is it possible to dynamically create variables in actionscript?for example lets say i have some kind of loop and for each itteration of loop i want new variable to be created, or acssed if creatin is not possible. ( tbh i don't need to create them dynamically there is more simple sollution of my problem in real project, am just wandering is it possible )[code]the best i could thought for acessing is filling them in array and acessing it like that.... code works but i am actually trying to make it work without array.[code]
View 2 Repliesi am loading several images from an XML path into a flash movie and i want to dynamically create image loader variables for them. Here is my code so far:
Code:
var xmlData:XMLList;
var myXML:XML;
var xmlLoader:URLLoader = new URLLoader();
[Code]....
method and this doesn't work for me either, i'm guessing thats because it is in the AS2 forum.
I am trying to create multiple variables from quite a big NOTEPAD / Txt file that would be constanly changing.The notepad file would look something along the lines of:heading1=Hello!&heading2=How r u?&heading3=Great Day... ... &heading50=WOOT!!!tc.I am trying to generate multiple variables in Flash MX 2004 for each of those "headings"n Flash I've tried things along the lines of:
loadTxt = new LoadVars();
loadTxt.load("headings.txt");
loadTxt.onLoad = function() {
[code].....
1. How could I make it where some images/text in a flash file is taken from another outside file. For example lets say I have a image and text that would need to change constantly. The image could probably be done by using a url and changing the image set to that url, but I would rather have it search for a images file name on my computer. For the text is there a way I could use a text document, and have it set up to take the text in that document and display it.
2. How can I make it so when I click a link to an outside url it doesn't confirm that I want to visit it.
I have a webpage where user enters details. These details are sent to php and session variables are created. My new swf then grabs these variables and displays them in a movie. Now the whole idea is for this movie clip with the details then to be sent to someone as a link. But, if the receiver then opens this link, they wont have the session variables though, and the details will not display.
View 1 RepliesHow flash setup a variable to handle the newly created movieclip?
Example:
this.createEmptyMovieClip("mymovie",2);
this.clientscroller.setScrollContent(mymovie);
Where did I set it up as a variable? I tried this and didn't work either:
this.createEmptyMovieClip("mymovie",0);
mymovie.createTextField("mytext",1,100,100,300,100 );
I have the code below but I need to generate it with a for loop. What is the proper way to do this? I don't initially know how many points i will have. I just want to create a for loop to loop through a variable that holds the point count such as "var totalPoints=10"
//1
var p1oint = new Point();
points.addChild(p1);
[code]......
Here is the structure of the XML file: PHP Code: <xmlfile><page></page><page> <source></source> </page></xmlfile> Some "page" nodes contain the extra "source" node. What I'm currently doing is looping through all the page nodes and looking for any source nodes. If there is a source node, I create a variable, and want to assign it a value of the contents of the "source" (HTML).
[Code]....
I'm still a noob with flash. But I'm attempting to make my website using itSo far I haveseveral swf files that are all loaded into a "index" swf file.So all the code needs to work with that chain of MC's:_root.LoadedContent_mc.LoadedContent2_mc.Page1_mcThats the path to where I am working..Page1:I'm attempting to create a downloads list here. I have a phpfile already worked out that scans the directories "downloads" and "imgs", and generates a list of file names. It then formats each file name into a path to that file. And turns each path into a variable that can be loaded into flash.So basically after php does its thing we are left with this:
Code:
File1=Pages/PageData/Page1/Downloads/SomeTextFile.rar&File2=Pages/PageData/Page1/Downloads/SomeTextFile1.rar&File3=Pages/PageData/Page1/Downloads/SomeTextFile10.rar&File4=Pages/PageDat
[code].....
So, I'm just starting a bigger AS3 project. I'm still learning AS3, transitioning from AS2 and I keep getting caught up on dumb stuff. I'm creating two variables to store a maximum and minimum value for a random number generator. Here's my code.
[Code]...
I'm working on a project that requires a numeric value to be stored in one scene and called in another- is this possible in ActionScript.
For example, I need to create a timer that times how long it takes for the user to preform the action, and save the value. In the next scene, I need that same value from before to be called in that scene.
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 RepliesHow do variables true/false custom variables work in flash?
For example, what I want to do is create a simple true=false variable that I can call on an if statement later.
For example:
Code:
Var1 = true;
if (!Var1)
{
[Code]....
I noticed that neither the "Var1 = true;" part or the if(!Var1) part worked in flash.
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.
View 5 RepliesI 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;
[Code]....
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.
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);
[code]......