Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




[AS2] Dynamically Constructing Variables Name



The title says it all.

For example if i have a variable called Current_Map (with values 1,2,3 etc depending on where the player is in the game)
And different arrays called Map1_Array, Map2_Array etc
How would i access a particular array?

I tried this but it dont work

trace(["Map" + Current_Map + "_Array"]);



Ultrashock Forums > Flash > ActionScript
Posted on: 2004-09-01


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Constructing XML Dynamically
Hi,

I have a variable and a string, which represents the position of this variable in the XML structure I need to create, for example:

variable is 10 and the string is company.name

The number of elements in the sering can differ. I want to create a function which would add this element to XML structure. here is the idea I tried, but without luck:

Code:
var myXML:XML = new XML(<rootNode/>);
var value = 10;

var str = "company.address";

var temp:Array = String(str).split(".");
var node_name = myXML;
for(var i:Number = 0; i < temp.length; i++){
node_name = node_name[temp[i]];
}
node_name = value;

trace(myXML); // not working

myXML[temp[0]][temp[1]] = value; // working
trace(myXML);
It seems to me that the cycle should do the same as the line before the last, however it doesn't. Any ideas?

Thank you.

Constructing Variables In Actionscript
I am trying to have a page read from a long and varied list of parameters and deliver the result to a dynamic field onscreen. Arrays are out for different reasons. Is there a way of doing it ? I was looping, having bob go from one to ten and then using

if(dr+"bob"+state==="OFFLINE"){do this);

but Flash refused to play. I then went to

drstate = dr+"bob"+state;
if(drstate==="OFFLINE"){do this);
And Flash told me that drstate equalled dr1state, rather than the contents of the variable I had (not) called.

Can Flash do this ? Am I just too dense ?

Any help appreciated.

Constructing Dynamic Variables In Flash
I have a flash movie that uses loadVariables() to get the results from a MySQL database, this side all works without any problem.

This above php script returns 3 image names from a database entry as follows:


PHP Code:



print '&work_img' . $work_id . '_1='            . urlencode($array[0]);
print '&work_img' . $work_id . '_2='            . urlencode($array[1]);
print '&work_img' . $work_id . '_3='            . urlencode($array[2]); 




These values all load as they should.

In the flash movie I use a function to set these variable values to the imageLoaders but here is my problem, I need to create the variable names dynamically as "work_img' . $work_id . '_1'" could be "img22_1.jpg", "img764_1.jpg" or whatever. In the flash file I am trying to get this values using:

Code:
var work_img_1 = "work_img" + entry_id + "_1";
var work_img_2 = "work_img" + entry_id + "_2";
var work_img_3 = "work_img" + entry_id + "_3";
but the "work_img_1" variable returns "work_img17_1", this tells me that the code * var work_img_1 = "work_img" + entry_id + "_1"; * has set a string to the variable "work_img_1" and not a variable called "work_img22_1" that returns the value of "img22_1.jpg".

Have I explained this clearly?

So... anyone know how I can create the variable "work_img" + entry_id + "_1" (work_img22_1) dynamically and not a string?

Thanks

Constructing A String
I want to have a frame with a line of code that directs the timeline to a certain scene depending on a variable's value.

example: (if varDestination = "scene2")

gotoAndPlay(varDestination);

I have tried this and it doesn't work, it just goes to the next scene.

I'm guessing I need to do something with a "+" and perhaps something that puts '"' around the variable to make flash read it like it is this:

gotoAndPlay("scene2")

help?

Would Appreciate Help In Constructing An Object
Hi.
I've done a couple of searches for tutorials and still haven't found a lead to how to do this correctly. I'm trying to make a tilebased board for a game (wargame).

this text was what i thought i had to throw in, following flash mx game design demystified's instructions - this book has proved troublesome before when coding in mx 2004 but I don't know if this syntax has changed since mx.

This code is placed in first frame and is supposed to create "an object" which I can use at several different places later in the code. However, when I later try to draw the tiled board, the app doesn't draw a thing - and the trace at the bottom of the code below, returns undefined. So I'm starting to think I got this construct new object-thing completely wrong. Would appreciate any help.

game = {};
game.columns = 10;
game.rows = 10;
game.spacing = 72;
game.depth = 1000;
game.path = _root.m;
game.types = 8;
trace(game.path);

Help With Constructing This Array?
I have been trying to condense code into an array because I have been told it is a more efficient way of doing things. However, I do not fully understand how to use the information in an array, and so I am getting an error whenever I try to use it.

Here is the original code I was trying to condense:

Code:
var Mirror:mcMirror;
var Calendar:mcCalendar;
var Clock:mcClock;

Mirror = new mcMirror();
Calendar = new mcCalendar();
Clock = new mcClock();


function mirror (event:MouseEvent):void {
(root as MovieClip).mainStage_mc.addChild(Mirror);
Mirror.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
Mirror.addEventListener(MouseEvent.MOUSE_UP, dropIt);
}

function calendar (event:MouseEvent):void {
(root as MovieClip).mainStage_mc.addChild(Calendar);
Calendar.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
Calendar.addEventListener(MouseEvent.MOUSE_UP, dropIt);
}

function clock (event:MouseEvent):void {
(root as MovieClip).mainStage_mc.addChild(Clock);
Clock.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
Clock.addEventListener(MouseEvent.MOUSE_UP, dropIt);
}

cogChar_mc.cogCharContent_mc.mirror_btn.addEventListener(MouseEvent.CLICK, mirror);
cogChar_mc.cogCharContent_mc.calendar_btn.addEventListener(MouseEvent.CLICK, calendar);
cogChar_mc.cogCharContent_mc.clock_btn.addEventListener(MouseEvent.CLICK, clock);


And this is how I tried to condense it:

Code:
var item:Array = [new mcMirror(), new mcCalendar(), new mcClock()];
var buttons:Array = [cogChar_mc.cogCharContent_mc.mirror_btn, cogChar_mc.cogCharContent_mc.calendar_btn, cogChar_mc.cogCharContent_mc.clock_btn];

for(var i = 0; i < item.length; i++){
buttons[i].index = i;
buttons[i].buttonMode = true;
buttons[i].addEventListener(MouseEvent.CLICK, itemMove);
}

function itemMove (event:MouseEvent):void {
item.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
item.addEventListener(MouseEvent.MOUSE_UP, dropIt);
MovieClip(root).mainStage_mc.addChild(item);
}


However, I now get an Error #1006 saying that addEventListener is not a function. Being new to programming concepts and Actionscript 3, could someone please explain what is wrong, and how to fix this?

Thank you.

Constructing A Paint Tool
Hello,
Would it be possible to have a help from you?
I need to build a tool to "tone up" to a childish website.
At the movie I'm using, I have the following structure:

1º frame / 1ºlayer - 4 different colors's buttons, red, green, blue e yellow.

1º frame / 2ºlayer - A cat's draw separated on two movieclips, 1 containing the cat's head, and the other the body.
Actually by clicking a button using a property I can change the color of one of the movieclips. But, what I really need is that:

By clicking in one of the buttons it stores a rgb color and release it on clicking one of the movieclips changing the movieclip's selected color. ( A tool which works as the "flash's paint bucked tool". )

Any suggestions/solution?

Icaro Brito

Strategy For Constructing Site
I'm building a portfolio site in Flash. Here's the basic layout: A window will display twenty large photos of my work. These images will appear when their coinciding link is clicked in the portofolio's menu. For instance, if someone clicks 'logo' in the menu, a large image of the logo would appear in the window.

Here's my questions:


1. What is the best way to optimize the loading of the images. Ideally, I'd like them to load only when they are called to appear in the window. This would avoid any heavy pre-loading when the site is visited.

2. Should the photos be placed into one Flash page, or should each photo get its own page?

2a. If all the photos should be placed into one Flash page, what is the best way to make them appear when their link is clicked?


Thanks,
TS

Constructing An 'if' Statement For Use In A Scroller
Hi, im trying to build a horizontal scroller which moves when untouched until you hover over one of the icons and it stops. This in itself is not the problem - I would like however, when you rollover an icon that a window appears either to the left or to the right (of the icon) depending on how far along the scroller the icon is.

A more complicated example of what I mean is on this site: http://www.evolvs.com

I was wondering how an if statement could be constructed to say (in laymans terms): if the icon is past a certain x position (on rollover), gotoandplay the animation of the window on the left, and if it is before this postion, play the one on the right. (the window is within the button itself so would appear relative to the button).

My files so far are up here : the window which appears on rollover is within button "1". Im using mx2004 but have saved them as mx. (oh, and it needs the .as file in the same dir as well).

Any suggestions would be great, thanks - it's mainly how to define the postion of the icons in actionscript i'm not sure about

Constructing ([a,b],[c,d]) Sort Of Array
I'm trying to constuct an array dynamically like

someArray = new Array([1,2],[2,3]);

Function starts like:
var someArray:Array = new Array();
for (i=1; i<20; i++) {

then none of the following worked:

someArray.push("["+i+","+(i+1)"]");
someArray.push([i][i+1]);
someArray.push([+i+(i+1)+]);

Since I want to construct the array actually with numbers, I shouldn't use quotes, but in fact what should be the way to achieve such thing?

Any help is more than appreciated.

Duplicating / Constructing New Functions?
I'm constructing a preloading script for use with loadMovie - unfortunately I can't use the MovieClipLoader class because I have to publish to player 6 on this occasion. I have a loop that runs through an XML file, collects image file names and then duplicates a clip as needed, loading a different image into each copy. At the same time I want a loop to run to check when each image has finished loading.

After staring at the screen for most of this afternoon, I'm wondering if the best way to achieve what I want is to duplicate a single function as required, and have different instances of the same function running (pseudo) simultaneously, but targeting different movieclips. I realise that I could simply place the function on the clip itself and duplicate the code with the clip, but I'd like to avoid this scenario if possible.

Can anyone give me some pointers as to the best way to do this, or at least tell me if I'm barking up the right tree?

many thanks!

Constructing A Date For Year 1AD
Hi. I'm accessing a .NET webservice with Flex. .NET does not accept null dates therefore sending a null date from actionscript causes an error in the request. What needs to be done is for me to send a date that the server will realise is meant to be null. The minimum date value in .NET is 01/01/0001 00:00:00. I would like to be able to send that but am having trouble creating it in actionscript. I have tried using a string - "01/01/0001 00:00:00" - but this is resolving to 01/01/1901. Thanks in advance for your help.

Newbie: Constructing An OR Condition
I have an application that gets passed a client ID, typically from 1-130.

This code works for client 34:


Code:
if (ClientID!=34) {
_root.ResPanel._visible=false;
}
But I want to add clients in the future, so it needs to say if you're
not client 34 or 50 or 75 then make the ResPanel invisible.

I've tried this but it doesn't work:


Code:
if (ClientID!=34 or ClientID!=1) {
_root.ResPanel._visible=false;
}
What should the correct syntax be?

thanks

Constructing Objects From UML Designs.
Curiousity.
I have to build a new flash application and I see the need for using objects. Typically I do a full design document on what is to be supported and how it will be done. In addtion variuos objects that will support the features are constructed via UML diagrams.

Question
Does Flash possess the ability to read UML designs and construct object files from them?

Constructing The Name Of A Movie Instance
I have a number of instances of the same movie in a frame. I have named all
this instances using the form : movieclipname1,movieclipname2...movieclipnameN
I want to control everyone of them so i have to reference everyone of them using it's own name .
Is it possible to use a loop where I will constructing the name of each movie ?
for example:
for (i=1; i++) {
with (movieclipname+1) {
play();
}
}
Is the above loop correct?
Thanks

Help With Constructing Cartoon In Flash
Hey,

I am creating a cartoon using Flash, I want to know - as each scene is kinda complex - what would be the easiest and most logical, in terms of using flash, way of constructing this task? Also note that there will be sound throughout this cartoon, infact its a song.

Would it be wise to use scenes and to just work on a whole cartoon in one .fla file OR is there a way of loading up movies one after another via a movie that would be the interface, which would hold the final product as a whole.

The options that I want to include while viewing the cartoon would be PLAY, PAUSE, STOP....so keeping this in mind what do you think? Initially i was thinking the 'loading of movies' option but now i am not so sure, and as there is a song that accompanies it throughout i'm worried about it being out of synch when i load up movies, etc..
thanks,

Sailesh

Constructing The Name Of A Movie Instance
I have a number of instances of the same movie in a frame. I have named all
this instances using the form : movieclipname1,movieclipname2...movieclipnameN
I want to control everyone of them so i have to reference everyone of them using it's own name .
Is it possible to use a loop where I will constructing the name of each movie ?
for example:
for (i=1; i++) {
with (movieclipname+1) {
play();
}
}
Is the above loop correct?
Thanks

Help With Constructing Cartoon In Flash
Hey,

I am creating a cartoon using Flash, I want to know - as each scene is kinda complex - what would be the easiest and most logical, in terms of using flash, way of constructing this task? Also note that there will be sound throughout this cartoon, infact its a song.

Would it be wise to use scenes and to just work on a whole cartoon in one .fla file OR is there a way of loading up movies one after another via a movie that would be the interface, which would hold the final product as a whole.

The options that I want to include while viewing the cartoon would be PLAY, PAUSE, STOP....so keeping this in mind what do you think? Initially i was thinking the 'loading of movies' option but now i am not so sure, and as there is a song that accompanies it throughout i'm worried about it being out of synch when i load up movies, etc..
thanks,

Sailesh

Constructing A Paint Bucket Tool
Hello,
Would it be possible to have a help from you?
I need to build a tool to "tone up" to a childish website.
At the movie I'm using, I have the following structure:

1º frame / 1ºlayer - 4 different colors's buttons, red, green, blue e yellow.

1º frame / 2ºlayer - A cat's draw separated on two movieclips, 1 containing the cat's head, and the other the body.
Actually by clicking a button using a property I can change the color of one of the movieclips. But, what I really need is that:

By clicking in one of the buttons it stores a rgb color and release it on clicking one of the movieclips changing the movieclip's selected color. ( A tool which works as the "flash's paint bucked tool". )

Any suggestions/solution?

Icaro Brito

Constructing A Month-to-view Calendar
I'm trying to create a mini-app that can show dates calculated on a calendar, similar to this one:
http://www.tiger.gov.uk/cgi-bin/mate...=Show+Calendar
Does anyone have any experience/tips on how to go about this. Basically, having generated a date I'd like to be able to dynamically create the months around it to give a more visual perspective.
I realise I'm going to have to work out from the date given what its position is relative to the start and end of the month, and week, and chart that somehow.

Any advice is much appreciated.

Cheers

Sam

Constructing Dynamic _level[num] Command
Hi, I have a little problem working with levels. I have loaded multiple audio clips in different levels 200,201,202,203,204.. The issue is that I want to play only one sound at a time and mute the sound that played last.

When new sound starts it tells old sound(level) stop and after that it reserves oldSound variable for itself. Main Problem is that I dont know how to construct proper command how to disable old sound:

sLev = Number(oldTheme) + 200;
lev = "_level"+[sLev];
trace(lev); //this prints: _level202
[lev]gotoAndStop("sOff"); //this dont work

if I try manually:
_level202.gotoAndStop("sOff");
//..it works fine.

Hope that someone knows this

Constructing A JPEG File In The Memory
Hi Fellows,

I need to do something a bit complicated, and I really dont know if it's possible. I would like to know if I can, at runtime (dinamically), load a JPEG file. But now the big deal: I dont want to load a JPEG file itself, but read a portion of bytes from somewhere and tell to Flash: "Hey, these bytes are a JPEG file, ok?"

Thanks!

[F10] Freeze-ups When Constructing Templated Vector Containers.
I am working on a project in flash 10 and have been migrating away from untyped Arrays to the new Vector.<> types. However I have had problems with the flash player hanging when constructing Vector.<>'s of some of my types. Hangups are happening even before I populate the container.


Code:
var sectors : Array = new Array; // Works



Code:
var sectors : Vector.<Sector> = new Vector.<Sector> // Hangs.


I am unable to determine the minimum environment necessary to reproduce the bug - some spots in my code work fine with Vectors<>, other places are hanging unless I stick to Arrays. Does the size of the template type matter? (in terms of #properties or #bytes) It was my impression that a Vector of a non-primitive type just stores references to structures carved elsewhere on the heap, so it's basically one word of memory for each thing you push in.
Or is there something else going on here? Like does a Vector<X> of size N require space for N instances of X, or N references to instances of X? The latter is correct, right?

Using Array's, the code was working fine everywhere - I just wanted greater type safety. Anyone have similar experiences or documentation hints on what I'm doing wrong?

Constructing A Quiz Using Flash Learning Interactions
Hello
I am looking at the creation of a quiz using the Learning Interactions in Flash.
I noticed that when I place say a Multiple Choice question on the stage that the area which says 'Question will appear here' is a dynamic text field.
This renders the final text bitmapped. Is there any way of getting the text to look like smooth like the rest of my work?
I have tried to anti alias it for Animation and Readability but it doesn't change. And in all honesty set against the rest of my work the text looks crap.
Thanks for any help you can offer.
PixelPilot

My First Attempt At Constructing A Simple Alpha Change Via Actionscript. Help
I have 4 movies that I would like to control their _alpha via buttons.

I believe I'm headed in the right direction, but when I test it, the Movie Clip is almost completely transparent. I would like it to be completely opaque when first loaded (ie. _alpha == 100)...


I've attatched the .fla if anybody has any thoughts on it....

Cheers,
Schimke

Dynamically Set Variables - Please Help
I am trying to create and set a variable dynamically in Flash MX but I get an error saying "Left side of assignment operator must be variable or property." This code works in Flash 5 but not in Flash MX.

for (Counter=0; Counter<21; Counter++) {
eval("PhomeColor"+Counter) = eval("_root.Pants.item.Element"+Counter+"Color").g etRGB();
}

Is there another way to do this?

Load Variables Dynamically
I'm attempting to load variables (text files) into one movie clip by clicking on a button in another movie clip. Anyone have any suggestions? All I've been able to locate is the loadVariables actionscript, which doesn't seem to work without something else...?

Any help would be appreciated.

Thanx,
-Paul

Dynamically Creating Variables.
I have an flash application that reads information from an XML file.
I have the following element in the XML file
<Attribute name="XConversionFactor" Value="10">

Now when this information is read from the XML file into Flash, is it possible to dynamically create an Actionscript variable by the name
XConversionFactor with initial value as 10.

At the moment, i have a if condition that checks the name of the Attribute element and creates a variable.

Is it possible to avoid if condition check?
Thankin you in Advance,
Jay

How Do I Duplicate A Mc That Has Variables, Dynamically?
How do i duplicate a mc that has variables, dynamically?

Referencing Variables Dynamically
easy one this, but I can't quite seem to get it.

I have lots of variables...

var1_thing
var2_thing
var3_thing
etc...etc...

and I want to mess with 'em all in a loop....

for(i=1;i<10;i++)
{
["var" + i + "_thing"] = "chocolate";
}

but I can't seem to get the right syntax... can anyone tell me what I'm doing wrong? ta!

Dynamically Naming Variables
I need to create a variable for each member of an array and set it equal to a certain frame in a movie clip nested within each array member. when i try to do the following:


Code:
this._name add "." add testlist[0+t] add "." add "score" = testcycle.slidermc.ball._currentFrame;


i get an error. hopefully you see what i'm trying to do. how can i accomplish this? thanks

Dynamically Naming Variables
I need to create a variable for each member of an array and set it equal to a certain frame in a movie clip nested within each array member. when i try to do the following:




Code:
this._name add "." add testlist[0+t] add "." add "score" = testcycle.slidermc.ball._currentFrame;
i get an error. hopefully you see what i'm trying to do. how can i accomplish this? thanks

Adding Variables Dynamically....
hi,

any help/ideas would be greatly appreciated!

i am trying to create a weekly planner so students can enter in the amount of time they spend on a number of activities (study/work/exercise etc) and see those times dynamically subtracted from 24hours pers day and then finally the day totals subtracted from the weekly total..

this is the code i have so far:


Code:
//variables
hrs1="0";
hrs2="0";
hrs3="0";
hrs4="0";
hrs5="0";
hrs6="0";
hrs7="0";
total_hrs="24";
//end variables

//this function defines the variables
defineVars=function(){
for (i=1; i<8; i++)
{
textEntry=eval('hrs'+i);//the name of the variable
textEntry.id=i; //the number assigned to the variable
}
}

//this function sets the names of the text fields on the stage
nameFields=function(){
for (i=1; i<8; i++)
{
theField=eval('act'+i); //the name of the input box
theField.id=i; //the number assigned to the input box
theField.text=textEntry; //the variable originally assigned to the input box which is 0

theField.onChanged=function(){
if(this.text=="") //this 'if' makes sure the text box always has the value zero to prevent total_hrs from displaying NaN
this.text="0";
doCalculation(this); //this runs the calculation function so that if they change the value back to zero it takes that into account
}
}
}

doCalculation=function(which){
total_hrs= 24 - Number(which.text); //this calculation will check the value of all text boxes, add them & subtract the total from 24
}


so at the moment it only subtracts the value of the active input textbox from 24.. what i need it to do is check the values of the other input textboxes, add them together and then subtract the total from 24 everytime one of the textboxes is changed..

i thought about creating an array and pushing the values entered into the textboxes into the array and then getting the calculation function to add the values in the array and then subtract that total from 24 but i soon realised that if the student edited one of the values in a textbox it just added the new value to the end of the array..

i know there must be a way of doing this but i'm all out of ideas!

i have attached the .fla in case more detail is needed...

hope someone can help.. thanks in advance!

sars

Dynamically Create Variables
Hey Guys!,
I got myself a problem. Its something I have been playing with a for a while but have not gotten to do something about it until now.

I need to create variables dynamically...
example:
Sometimes I need to create multiple variables.
testVar1 = 10;
testVar2 = 10;
testVar3 = 10;
so on....

Now this can get ugly and takes me allot of time. I need to be able to create variables dynamically. Like bellow where "n" is a variable.
testVar[n] = 10;

I have tried allot of variations with little luck.
HELP!, Flash Gurus!
Take care,


N.D.

Referring To Variables Dynamically
Hi

I'm just starting out with action script so forgive me if any of this is obvious.

I am currently working on a simple logic puzzle involving a punch card.

Currently I have a graphic for the card which contains six buttons, for the punch holes.

What I want to do is have a pre set combination of punches which will solve the puzzle.

To this end I have created six variables for the current status (punched or unpunched) of each button, and six varriables containing the correct status of each button.

here is the solution I have been working on

code:

function punch (buttonNo) {
trace ("hole " + buttonNo + "was punched");
if ("punch" + buttonNo + "Status" == true) {
set("punch" + buttonNo + "Status", false);
} else {
set("punch" + buttonNo + "Status", true);
}
}



as you can see what I have done is to define a function which simply coverts between true and false, the problem being the way i reference my varriables.

The status variables are named punch1Status thru punch6Status, so in my function's 'if' and 'else' statments, I have attempted to reference them dynamically by cocatenating the buttonNo (a property which contains the number of the button punched) with the text elements from my varriable name.

This method seems to work when using the set() function but what I need is away of using this dynamic reference format without altering the value of the varriable.

Being a begginner I would appreciate any feedback, please let me know if I'm going about this completely the wrong way.

Many thanks in advance

P.S.

As I write it has just occurred to me that it would make sense if there was an operator which would simply convert between true and false, can anyone tell me what that operator might be?

Dynamically Assigned Variables
Baesd on the the code below, for a popup window on a button click

on (release) {
getURL("javascript: void window.open('http://www.website.com/index.htm', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,men ubar=0,resizable=0,width=500,height=250,left=312,t op=100');");
}

Id like to replace the path for 'http://www.website.com/index.htm' with the variable 'popUp',

and the window property code (the 'toolbar=0,scrollbars=0,location=0,statusbar=0,men ubar=0,resizable=0,width=500,height=250,left=312,t op=100')
with the variable 'windowProp'

I have both variables defined in an external XML doc, and successfully importing into the swf.

The variables are defined with the appropriate formatting for thier use, so that the 'popUp' variable returns an formatted absolute URL, and 'windowProp' variable returns a string like ''toolbar=0,scrollbars=0,location=0,statusbar=0,me nubar=0,resizable=0,width=500,height=250,left=312, top=100'


so in pseudo actionscript, the code example from above would logically be something like:

on (release) {
getURL("javascript: void window.open('popUp', '', 'windowProp);");
}

the issue is that the varibles, even thought they are importing the correct data, dont work as intended with the event.

Can anybody have an idea for the correct syntax/form? Im not sure how to strip these items together

thnx for reading - Mike Halak

Dynamically Creating Variables?
Hey, i was wondering if it would be possible to perform this code...


Code:
var point1 = { x: p1._x, y: p1._y};
var point2 = { x: p2._x, y: p2._y};
var point3 = { x: p3._x, y: p3._y};
var point4 = { x: p4._x, y: p4._y};
var point5 = { x: p5._x, y: p5._y};
var point6 = { x: p6._x, y: p6._y};
var point7 = { x: p7._x, y: p7._y};
var point8 = { x: p8._x, y: p8._y};
var point9 = { x: p9._x, y: p9._y};
var point10 = { x: p10._x, y: p10._y};
var point11 = { x: p11._x, y: p11._y};
var point12 = { x: p12._x, y: p12._y};
var point13 = { x: p13._x, y: p13._y};
var point14 = { x: p14._x, y: p14._y};
var point15 = { x: p15._x, y: p15._y};
var point16 = { x: p16._x, y: p16._y};

map = [point1, point2, point3, point4, point5, point6, point7, point8, point9, point10, point11, point12, point13, point14, point15, point16];
in a for loop? The p1 - p16 movie clips are already placed on my stage with the proper instance names. Thanks.

Creating Variables Dynamically
Hello
I want to create some variables durin run time.
for example
_root.text_3
_root.text_9
_root.text_7
the structure is _root.text_<number>
Can I do this in actionscript?

Dynamically Produced Variables
Hi all

I'm making a website that produces random compositions of 20 MCs as the background. Accessing the different pages will make the MCs move to different locations.

I'm using a for loop to attach the MCs to the stage and in order to make them smoothly change position when navigating, I need to produce a series of variables that determine the x and y positions. Is there a way of producing multiple variables within the for loop. I tried the following but to no avail:

Code:
var ["xPos"+i]:Number = 250 - (Math.random() * 500;
Thanks in advance

How To Dynamically Create Variables
I want to create some variables dynamically:


ActionScript Code:
for  (var i= 1; i <= 15; i++)
    {
    var "newVar" + i = i;
   
// if I can strict type the variables to a particular data type, that will be great too.
    }

Of course the above code is incorrect, but it illustrates what I would like to accomplish--dynamically created variables.

Naming Variables Dynamically
hi all, first thanks for all your continued support but i have run in to another problem, i have writtin a function that brings in a variable called "named" (this is a string) i want to use this string to be used to name my newly attached movieclip, so i can control it/remove it when i want.

any way the code i have is


Code:


function = Buttons(but:MovieClip, func, named) {
inv = but.createEmptyMovieClip("inv", 1);
inv.attachMovie("button", named, 2);
named._alpha = 50;
named._x = 0;
named._y = 0;
named.onPress = function() {
func();
};
}
so in theory named wants to be what ever string i have brought in, can this be done??

if my example makes no sense all, i just need to know how i name a variable dynamically!!!

Cheers guys Sam

Create Variables Dynamically / On The Fly
Hi everyone,

I'm trying to do what I thought would be the simple task of creating some variables on the fly, based on information that exists within an array -


Code:
var portfolioItems:Array = ["portrait", "landscape", "panoramic", "nature", "corporate"];
//
//
I basically want to create a load of new arrays like this -


Code:
var portraitGalleries = new Array();
var landscapeGalleries = new Array();
var panoramicGalleries = new Array();
var natureGalleries = new Array();
var corporateGalleries = new Array();
var landscapeImages = new Array();
var panoramicImages = new Array();
var portraitImages = new Array();
var natureImages = new Array();
var corporateImages = new Array();
How can I do this? I've set up the loop but what's the code to create the variables!?


Code:
for (i=0; i<portfolioItems.length; i++) {
// put code in here to create all the array variables
var [portfolioItems[i] + "Galleries"] = new Array(); // doesn't work
}
Thanks!

Matt

Defining Variables Dynamically?
Is there a way to pass a variable to a movie clip dynamically ? Otherwise, I'll have to declare each variable separately inside every movie clip... It's not much of a work but it would really be great if I could simply pass that variable to every movie clip with the help of a loop.

Any feedback is appreciated.

Dynamically Declared Variables
Hey all,

I am running into a problem with dynamically declaring variables. I need to declare an unknown number of variables inside of a loop, but still have access to those variables outside of the loop.

The closest I can come to a solution is:


ActionScript Code:
var total:uint = 3;
for (var i:uint = 0; i < total; i++)
{
    this["variable" + i] = "text " + i;
    trace(this["variable" + i]); // "text 0", "text 1", "text 2"
}

trace("variable0 = " + variable0); // 1120: Access of undefined property variable0.
trace("variable1 = " + variable1); // 1120: Access of undefined property variable1.
trace("variable2 = " + variable2); // 1120: Access of undefined property variable2.

But in this example the three trace statements produce errors because the dynamically assigned variables have fallen out of scope. Is there a way to maintain these variables outside of the for loop?

Thanks in advance!

Dynamically Creating Variables
Hey Guys!,
I got myself a problem. Its something I have been playing with a for a while but have not gotten to do something about it until now.

I need to create variables dynamically...
example:
Sometimes I need to create multiple variables.
testVar1 = 10;
testVar2 = 10;
testVar3 = 10;
so on....

Now this can get ugly and takes me allot of time. I need to be able to create variables dynamically. Like bellow where "n" is a variable.
testVar[n] = 10;

I have tried allot of variations with little luck.
HELP!, Flash Gurus!
Take care,


N.D.

Can I Dynamically Create Variables ?
same as topic.. Example:

for (i=1;i<10;i++) {
var this["myVariable"+i]:Number = 5;
}
I know this won't work and create for me 9 variables and all of them with value of 5 and exactly cuz of that I am asking if there is a way to dynamically create variables .. so I don't have to type manually 100 different variables that I need....
So.. is it possible and how ?

thanks

Dynamically Declaring Variables In AS3
Hi.

I'm trying to migrate from AS2 to AS3 and have stumbled on this. I can't find how to create dynamically referenced variables in AS3. Can anyone give me a hand? Thanks!

Here's the code I used in AS2:







Attach Code

//AS2
for (var i:Number = 0; i < 10; i++) {
this["myThing" + i] = new Object();
}

Dynamically Naming Variables In AS 3
Hello all,

I am having some issues dynamically creating/naming variables. I've seen plenty of posts on this for prior AS versions. But how the heck do I go about this in AS 3? I'm certain that this is wrong but I am looking to go about it some way similar to this:


Code:
var i:Number;
var _i:*;
for (i=1; i<11; i++) {
var _i:SomeClass = new SomeClass();
}
I am certain that the wrongness of this code will make some of you cringe. But please forgive my ignorance as I try to work through this. I am just trying to streamline my code a bit.

Thanks in advance.

Dynamically Declaring Variables
I have a loadvars object that has a number of properties called member1, member2 etc. They need to be transferred to variables but since I don’t know how many memberN properties there will be for the Loadvars object I don’t know how many variables to declare.


ActionScript Code:
for (var g = 1; g<=num_members; g++) {
this["current_member"+g] = l_members["member"+g].split("¸");
}


The code to the right of the “=” sign works fine but not the code on the left.

My thinking when using “this["current_member"+g]” was to use array notation (like the old eval function) to reference a variable called current_memberN. But since I haven’t declared the variable it would create it since variables that are not explicitly declared come into existence when first used (or does that rule no longer apply with AS2?)

I tried it and it didn’t work.

So I tried using something like>

ActionScript Code:
Var ["current_member"+g]


But it created a syntax error so I can’t do that.

The only other way I can think of is to create an object and then use array notation to point to a property.

ActionScript Code:
var myobject:Object = new Object();
for (var g = 1; g<=num_members; g++) {
myobject["current_member"+g] = l_members["member"+g].split("¸");
}


But since the property called current_memberN does not exist yet I may still face the same problem as my first approach.

Any body have any ideas on how I could overcome this problem?

Copyright © 2005-08 www.BigResource.com, All rights reserved