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




[F8] Use Variable To Refer To Object



I have a variable called current_slide and new_slide which I am using to determine which slide to display. When current_slide changes, I would like to turn visibility off on current_slide, and turn it on for new_slide. I am having trouble getting this to work.

e.g.
current_slide = "welcome";
new_slide = "location";

new_slide._visible = true;
current_slide._visible = false;

Flash is not realising that I would like to use the value of the variable to determine the object I am referring to. If I use location._visible it works fine.

How do I use a variable to refer to an object?



FlashKit > Flash Help > Flash Newbies
Posted on: 09-20-2007, 01:57 AM


View Complete Forum Thread with Replies

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

How To Refer To An Object Through A Different Name/variable?
Let's say I have a:


Code:
var drawing_layer1:Shape=new Shape();
How do I then say something like:


Code:
selectedLayer = drawing_layer1;
So that in my code, when referring to drawing_layer1 I can enter selectedLayer ?

I know this is an easy task for you guys but I am noob lol

How Do I Refer To A Object Or Variable Dynamically
Here it what I am trying to accomplish.

I have a few variables:
var x = "Crazy";
var y = "NotCrazy";
var superCrazy;
var superNotCrazy;

How do I do something like this:
"super" + x = "anything";
"super" + y = "whatever";

So that:
superCrazy = "anything";
superNotCrazy = "whatever";

This is how I imagined actionscript able to access variables and objects dynamically. But I get an 1123 error and I believe the error points to something only available in AS1.

So, how do I do this in AS3....hmmmmmmm!!

Refer To Object From Different Classes
Im using a document class to make a connection to a CMS using a class called DrupalSite, like this:
drupal = new DrupalSite(gatewayUrl, apiKey);

This connects to an AMFPHP interface and allows me to use various methods to get stuff from my CMS. In that document class I import other classes to do things like layout buttons etc. i.e.

import com.build.Layout;
...
private var layout:Layout;
...
layout = new Layout();
addChild(layout);

How do i refer to the object 'drupal' that i created from the imported classes, for instance the layout class. The methods i want to use are things like drupal.getnode on event handlers in layout.as.

How To Dynamicly Refer To Object?
Okey, "_global.tracker" in an integer, "currExhibition" is a string, and "_global.selObject" is supposed to be a referer to an object. But that code seems to generate a string, so how can I "objectify" it?


Code:
quicke.next_btn.onRelease = function() {
_global.tracker ++;
_global.selObject = [currExhibition + _global.tracker]; //how to do this?
attachProps();
loadSomething();
_root.cb = 0;
}
Probably something easy, I just hope you guys understand what I´m trying to do

Refer To Variable In Timeline Of Same MC?...with
Hi!
I have a complex project-structure with several MCs nested on two levels. Now I'd like to call a variable that is actually in the same MC where I call the variable from (hope that is clear...). I don't want to put the whole absolute path in (like _level2.MC1.MC2.myVariable etc.). Can I refer to the variable with the "this" keyword instead? And how exactly do I have to do this? I can't figure it out.
thanx very much!
mink

Using A Variable To Refer To An Instance Name
How do you use a variable to refer to an instance name? I have a number of clips with the instance names of T1 through T9, and I want to start them based on variable x. Eval function?

Sorry if this has been asked before - I did a quick search and couldn't find it.

Using A Variable To Refer To A Declaration
I am getting a bit confused with fundamental actionScript conventions in order to play a sound object (by using a variable made up of a string and a value to refer to a declaration)...

A sound object for my music player has been declared as myTrack1

On the play button, i set this variable CurrentTrack = myTrack1 and therefore the instruction
CurrentTrack.start(0,999) makes the sound object play as expected.

I have another variable which is nowplaying which has a value 1, and increments everytime you press fast forward.

My problem is that I want the variable
CurrentTrack = "myTrack" + nowplaying
(so that it will play myTrack1, or myTrack2, myTrack3 etc depending on if you have fast forwarded)

Even though the resulting text of CurrentTrack is still "myTrack1", it doesn't have the same effect as when I set CurrentTrack = myTrack1

I assume this is something to do with it being a string rather than a value or something, but I can't figure out how I should put it so that it will work

Hope someone can shed some light, thanks in advance

Refer To An Instance Through A Variable?
don't know if this is possible and if so how do i do it...

can1 is the name of the instance

asdf("can1")

asdf = function(name){
name._alpha = 100%;
}

how do i convert that variable so flash will know that i am referring to that instance?

Using Variable To Refer To Instance Name
I'm trying to find a way to refer to an instance name in an "if" statement using a variable.

I have several similarly named movie clips, and if I can use a variable to refer to them, I won't need to write an if statement for each mc. Here's what I've tried, but it hasn't worked. In this example, I want the if statement to refer to image1:


ActionScript Code:
imageNumber = 1
if ("image"+imageNumber._width>1) {
        fadeIn = true;}

I would greatly appreciate any suggestions. Thanks.

Refer To MC On Stage With Variable?
Hello.
I am wondering how I could achieve this:

I am trying to get the _x value of a MC on Stage through a variable name. This is what I've tried and then you'll get what I'm trying to do:

Code:

var objItems:Array = new Array("main" , "main2");
var numOfObj:Number = objItems.length;
for(var i = 0; i < numOfObj ; i++) {
   trace(objItems[i]._x);
}

So on stage, I have two MCs named "main" and "main2" and yes, I can get their _x by hard coding it but for updating sake, I put them in an array, and would love to get their _x values by using or utilizing the array somehow.

When I look at the trace, it returns both "undefined" so I'm guessing that it thinks it's a string and retreiving its _x value which doesn't exist... How do I translate that string into a MC name that can be recalled?

I hope this is even possible!
Thanks,
Keehun

Update:
I've tried:
Code:

var objItems:Array = new Array("main" , "main2");
var numOfObj:Number = objItems.length;

for(var i = 0; i < numOfObj ; i++) {
   var mc:MovieClip = objItems[i];
   trace(objItems[i]);
   trace(mc);
   trace(mc._x);
}

The trace for:
objItems[i]
mc

works but trace for:
mc._x does NOT work.

How Do You Refer To An Object In The Stage, From A Class, In Flash CS3/AS3?
In Flex 2, 'mx.core.Application' does the trick.
was wondering, 'flash.display.Stage' might work in Flash, but it fails.

How do I refer to a MC named 'ball' in the stage from within a Class?

Its Possible To Refer To A Variable In Scene 2 With The _root?
Hi there.
Basically, the problem is this.
I have a swf with two scenes, i want to access in scene 1, a variable that is declared in scene 2, and vice-versa.

I also want to know how to, assuming that im in scene 2, how to access vars on this same scene being for instances, inside a movie clip...
Its like this, if i use _root, the flash assumes i'm acessing a ver on Scene1, not on two.

Please help me!!!
Thanks in advance!!

Ricardo
Portugal

Using Variable Value To Refer To A Movieclip On Stage
Basically I have a variable in which I store various numbers depending on other aspects of the flash movie and I have a bunch of movieclips that are on the stage all named by number.
I want to use the variable value to access and run methods etc of these movieclips.

e.g.

var myVar = "10";

myVar.myFunction();

where the item on stage called '10' will react. I realise this is a confusion between a string and an object/movieclip reference but i'm almost certain ive done this before and ive got a feeling it had something to do with [ ] brackets on the end of something...

sooo frustrating when you can't remember stuff

How To Use A Variable To Refer To A Movie Clip Instance
I have a movie clip I am calling from several other movie clips. I need to return to the movie clip that called it when it is finished. How can I use a variable in conjunction with gotoandplay. I have tried using a string to hold the instance name... no go. Works fine if I enter the actual movie clip name. But I really need to use a variable to avoid a huge if statement.

Refer To "parent Object" In Listener Function
Hi there!

I just want to set the attribute of the new Test object instance from inside the listener function.
"this" refers to the XML object in this case, not to the new Test object...
Any help?


ActionScript Code:
class Test {
    var attribute:Number;
   
    function Test(file:String){
        var myXML:XML = new XML();
        myXML.load(file);
       
        myXML.onLoad = function(success){
            if(success){
                //set attribute here
            }
        }
    }
}

AS3 - How To Refer To An Object In A Class From Within The Class
I have a little question here.
How can I refer to an object in a class from within a class? Here is what I’m trying to do:
In my class I have created a movieclip variable and I have give it a name:

var myBox:Box = new Box(); // Box is a class that extends MovieClip
myBox.name = "box" + _boxNum;
_boxNum++; // I need to give the variable different names because it’s created in a loop and later I would need to call by their instance names
addChild(myBox); // I have added new myBoxes to the class.

Now I’m trying to call one of the myBox instances from their name. I’m using these two, but they doesn’t seem to be working!
var tmp:Sprite = getChildByName("box" + _defaultItem).getChildByName("bg_mc").getChildByName("selectedBg") as Sprite;
var tmp:Sprite = this.getChildByName("box" + _defaultItem).getChildByName("bg_mc").getChildByName("selectedBg") as Sprite;

Please note that the other getChildByName works, it’s just that the first one only doesn’t work!

Regards,
Hadi

_root.variable -> Object Variable
Hi,
I am rather new to flash, so please bear with me

I've downloaded a flashmovie at http://www.flashkit.com/movies/Inter...8449/index.php ( a very beautiful window navigation menu).

The menuitems to build this window-menu are placed within the object as variables.

I want to put these variables into the root timeline (where I can retreive menuitems from a database). The object however cannot retreive variables from the root-timeline it appears.

I've tried using _global.varname in the root timeline, but it didn't help.


Is there a way I can make these variables appear within the object?

help appreciated
Patrick

Name Object From Variable
How can I create an xml object (or any object in fact) named after a variable,

i.e

variable called section with value "names"

create object [section value + "XML"] = new xml();

result: empty xml object called namesXML

Get Variable Out Of An Object
Hi evryone,

I have a code that generates an object. In that object, there is another object, en in that object, there is a var. So it is:
game.currentmap.vgoals . Now I want that a dynamic txt field shows the value of that variable. But fe: if I use:

Code:
function updateStats() {
_root.tempVgoals= game.currentmap.vgoals;
_root.totalgoals = game.currentmap.goals;
}
it wont work.

So the dynamic txt field's var names are tempVgoals and totalgoals. The function is executed in an onEnterFrame. If I trace "_root.tempVgoals", it gives out the wright value, but it still wont appear on my screen.

Please help me

With kind regards, Dauntless

How To Name An Object With A Variable?
If I have the following

myObject = "ball";

How do I make an object called "ball"?

The following does NOT work, instead it makes an object called 'myObject':

var myObject:Object = new Object();

I've heard I can make 'variable variables' with eval(), but the following throws an error:

var eval(myObject):Object = new Object();

PLEASE HELP. This is driving me crazy.

Using A Variable To Specify An Object
I am going through the tutorials in the "learning actionscript 3.0" book by Rich Shupe.

I got to a tutorial in chapter 3 that deals with adding event listeners. It is based on a project file that contains a movieclip called "box" and a number of buttons to perform different transforms on the box (move up, move down, scale up, etc.). They are named "move_up_btn", "move_left_btn", and so on.

Now I got through the exercise fine, but I like to try and expand on these examples to test my comprehension. The original code for each button goes like this:

move_up_btn.addEventListener(MouseEvent.MOUSE_UP, onMoveUp);

for the listener, and then

function onMoveUp(evt:MouseEvent):void {
box.y -= moveStep;
}

for the associated function.

I was thinking I could make this more dynamic by having the listener pass the name of the target object from the listener to the function instead of having it hard coded into the function. This way I could have several listeners for different objects use the same function. I tried to modify the code to accomplish this, like so:

move_up_btn.addEventListener(MouseEvent.MOUSE_UP, onMoveUp("box"));

and for the function:

function onMoveUp(transTarget:String):void {
transTarget.y -= moveStep;
}

This doesn't seem to work. Flash looks for the "y" attribute of the transTarget object, which of course it doesn't find since transTarget is a string variable. What I want it to do is see transTarget as a variable and use it's contents as the target object to modify the "y" attribute of. Can anyone tell me how I would do this?

Also, on another note, in the original function, I didn't quite get why it has "evt:MouseEvent" as the input for the function, is the listener passing the mouse event to the function instead of just calling it? What is the purpose of this?

Thanks in advance for any help.

Variable Object Name
Is there anyway to have a variable object name? Such as
Code:
["event"+i] = new Object();

Variable Name As Object Name
Hi. I'd like to be able to create some variables dynamically in AS3 and then use them as object names. For example, to create the variables circle1, circle2 etc I write:

for(var i:Number = 0; i < 10; i++)
{
this["circle" + i];
}

I would then like to create movie clips with the names of these variables so that I can add them to the stage and access their properties individually. Is this possible?

Using Variable Value As Object Name... Help
This shouldn't be too hard for someone with a little more experience...


ActionScript Code:
stuff = setInterval("fun",20);myVar = "stuff";clearInterval(myVar);


Obviously, the above clearInterval won't work, because the clearInterval looks for "myVar" instead of "stuff". I want it to be the other way around.

I tried using the following, but with no luck.

ActionScript Code:
clearInterval(this[myVar]);clearInterval(_root[myVar]);

How To Get A Variable From The Object Tag
I need to get a variable from a param in the object into flash and apply it to the onclick event for a button. Can anyone help me out with that? Snippet below


Code:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="320" height="240" id="source" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="flashVars" value="urlToGoTo=http://myurl.com" />
<param name="movie" value="http://myurl.com/Controls.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="http://myurl.com/Controls.swf" flashVars="urlToGoTo=http://myurl.com/" quality="high" bgcolor="#ffffff" width="320" height="240" name="source" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"/>
</object>
This is the variable I have to capture and apply to a button.
urlToGoTo

As always thank for any help.

How To Use Variable In Color Object?
I would like to use a variable in the color object but dont know how to. What I am using is:
myColor = new Color(bg);
myColor.setRGB(bgcol1);
Here the RGB value is stored in the variable bgcol1 which is '0xffffff'. But its not working. I am getting the variable bgcol1 from a database. Is there a way to use the variable in the color object?? I have a book in which I want the pages in different colors and so I have taken a variable bgcol in the database and bgcol1 corresponds to page 1's color and so on. I am being able to get the correct values in the variables but somehow in the color object it doesnt work. Kindly help.

Naming An Object With A Variable
I have a square that is broken into four equal parts. The function that I have makes it so that they scale relative to each other in that when quadrant a gets bigger the quadrants below (c,d) decrease in height and the quadrants to the right(b,c) decrease in width. I have this working really well but I want to have multiples of this same efect throughout the page. I just want to set the name as "a"plus the variable "i" so I can just set the function up

a(i)._xscale= x;
a(i)._yscale= y;
b(i)._xscale=200*(1-(x/200));
b(i)._yscale=y;
etc...
But I don't know how to name a mc with a variable.
I hope this is clear. Anyway thanks for the help in advance.

Add A Variable To A Movieclip Object?
If I load a moviclip/button to a movie, can I add a variable to the movieclip/button object?
I'm populating a movie with a bunch of clips that are just duplicates of a movieclip which act as a hyperlink. I can store the text of the hyperlink in the object.label variable, but I have a record id that has to be stored in some other variable for THAT specific movieclip/button. How can I do that?

Replace Object With Variable
Hi,

My .fla contains the following script:

Code:
comboBx3.setSelectedIndex(9);
var varBx;
var numberBx;
numberBx = "4";
varBx = "comboBx"+numberBx;
varBx.setSelectedIndex(9);
stop();

"comboBx3.setSelectedIndex(9);" works fine but "varBx.setSelectedIndex(9);" doesn't seem to work.
Variable varBx contains the objects name "comboBx4".
When I replace varBx with comboBx4 it works but that isn't what I want of course.

Can anybody PLZ help my out?!?!

THX

How To Add A Variable To A Sound Object
Hi,

How can I store a variable inside a sound object. Forexample is this possible ?

var sndSound = new Sound();
sndSound.strVar = "SoundName";
trace(sndSound.strVar);

IS there a way to retrieve the name of the attached sound inside the sound object.

Thank you.

Object Instance > Variable Name
Hi all,

Ok, I have be faced with this problem so many times. Sometimes my workarounds work, sometimes not. But here we go:

I want to be able to store an objects instance name in a variable, and then reference that object elsewhere with the variable.

So,

onClipEvent (load) {
instName = "textFieldInstanceName";
}

then within that movie clip:

_parent.instName.scroll += 1;

I've tried this, but no dice:

_parent.eval(instName).scroll += 1;

I bet someone is looking at that syntax and laughing it up.

Anyways, I'm hoping someone can see what I'm trying to get at here and can tell me the proper way to handle this kind of situation as it always seems to come up for me.

-Blake

How Do I Get The Object Reference Of A Variable?
I have a few long named variables with long paths.

Can someone tell me how I can create a new short name variable and assign it to the reference of the long named variable?

Erm... perhaps I'm not being clear.

I have the following variable say:

myMovie.anotherMovie.holdingMovie.myVariable

I want to create another variable called:

shortVar

When I change the second, I want this to change the value of the first as well because in memory they point to the same variable stored in memory.

Hmmm does that make any sense?

Any help would be appreciated.

Thanks.


OM

Replacing Object With Variable
I load a .txt file into a variable called picData1... that works fine this way:

I define the variable picData1...
m_alquileres.picData1 = new LoadVars();

the, inside a function i have this code to load new data on picData1...

p=m_alquileres.picData1;
p.load("picdata"+(_global.n)+".txt");

this piece of code works perfect.. but now comes the problem:

I want to make something like the next example, but didn´t found the way to make it work: (´targetmovie´ is the name of the movie i pass to the function, like "m_alquileres", or "m_ventas"....)

..function (targetmovie)..
p=targetmovie+".picData1";
p.load("picdata"+(_global.n)+".txt");


All I want is to target picData1 at diferent movies. This way i can call the function which populates data telling which movie must be populated each time.

How can I do it?
Should it work? must I use a special way to define ´p´ ??

(MX 2004) Specify Object With Variable...
Hi.

I'm hoping this is just a simple operand that I just am not aware of.

I am trying to use a rollover to both define a variable:

city = ("Atlanta");

and then use that variable to command a MovieClip whose instance name ("Atlanta") is the value of that variable:

//something like

city.play();

Could you help me?

Thanks!

[MX04] Specifying An Object By Using A Variable
Hi.

I'm hoping this is just a simple operand that I just am not aware of.

I am trying to use a rollover to both define a variable:

city = ("Atlanta");

and then use that variable to command a MovieClip whose instance name ("Atlanta") is the value of that variable:

//something like

city.play();

Could you help me?

Thanks!

Using A Variable To Specify An Object Property
Hey all,

Suppose I have

columnName : String = 'name';

and then I have a dataGrid that I want to add an item to via:

dG.addItem({columnName:'joe'});

This creates a column called "columnName". Is there a way to use the value of the string "columnName" instead as the column title?

Thanks in advance!
fitz

Duplicating An Object Using A Variable
I'm quite new to AS3, and I've run into a problem that I can't solve.

I need the facility to duplicate an object from a variable. The reason for this is that I will be creating a large number of different objects that need to be duplicated, and do not want a separate duplicate function for each one.

This is what I have right now. The ObjectType:String is delivered by a button, and is then duplicated. However, this does not work. Is it possible to do this? or is there another method?


ActionScript Code:
function duplicateObject(objectType:String):void {
//uses the objectType string to determine what object to duplicate
    var newObject = new objectType();
    this.addChild(newObject);
}

Thanks in advance!

Load Variable Object Help
I am having trouble loading my variables into my mc BioInfo, this is my code so far:

Code:
MyLoadVars = new loadVars();
MyLoadVars.load("D:MultimediaProjectsRiversideCdTypes12667Bio.txt");

Error opening URL "D:ultimediaProjectsiversidedTypesV67Bio.tx t"

How To Use A Variable As Object Name? In Actionscript?
I am working on a flash menu and have a problem in it.
here is the code i am using.
I wanna use the variable mnu instead of this[mnu] but do not know how to do it. Any body can help me?







Attach Code

var mnu = 'menu1';

this[mnu].onRollOver = function(){
var loTween_x = new Tween(this, "_xscale", Regular.easeInOut, 100, 150, .5, true);
var loTween_y = new Tween(this, "_yscale", Regular.easeInOut, 100, 150, .5, true);
trace(mnu);
}

Using A Variable To Reference An Object
Hello all,

I desperately hoping someone can shed light on my problem. I am trying to reference a movieclip with a variable. I've done it before but in loops reading from xmlobjects but cannot get it to work in the most simplist way....??

var i = 0;
_root.movie[i]._visible=0;

should be just the same as

_root.movie0._visible=0;

should it not?

I have attached the .fla

thanks so much to anyone who can help me on this..its killling me...

Variable Object Referencing
Hello, I just stumbled across your forums today looking for an answer to my question on Google.

I am in no way very knowledgable with ActionScript, so this might be very simple and I am looking in all of the wrong places... but basically here is my issue:

Instead of accessing an objects attributes like this, _level0.thumbnails.thumbnail0._width = 500;

I want to be able to access it with _level0.thumbnails. (this.id) ._width = 500;

where as (this.id) is a variable that could be equal to "thumbnail0" or "thumbnail99" depending on which object gets clicked. I have everything working to if I hardcode thumbnail0 it works fine, and this.id does get set to whatever thumbnail I click's "thumbnail" + ID

... any help?

Using A Variable To Reference An Object
Hello all,

I desperately hoping someone can shed light on my problem. I am trying to reference a movieclip with a variable. I've done it before but in loops reading from xmlobjects but cannot get it to work in the most simplist way....??

var i = 0;
_root.movie[i]._visible=0;

should be just the same as

_root.movie0._visible=0;

should it not?

I have attached the .fla

thanks so much to anyone who can help me on this..its killling me...

Object Variable Not Recognised
Hi,
I'm trying some old script to classes...I had a global boolean variable called subtitlesYes , which I want to declare as the property of an object...It has to be readable by several levels of swf's which are loaded and unloaded at different times.
I put this in an as file, in the same directory as the swf's :
             
class ipa{
    var subtitles : Boolean;

    function ipa( subtitlesYes : Boolean){
        subtitles = subtitlesYes;
    }
}

In the root movie I put in the first frame:

var dpp : ipa = new ipa(false);

and then later on a level 3 swf, I had this:

if( dpp.subtitlesYes == false){
           _level3.speech._visible = false;
};

then in publish settings for as2 I put the document level class path in; ie. the same directory path as where the swf's are stored. I've put the path into all the swf publish settings.
   And it all doesn't work though the compiler doesn't complain of anything...
   Thanks so much if you can help, silverswim
     

Object Reference W/variable
This has been asked before, I've even had a similar problem before, but it's not working this time. Basically I have a MCL that works fine, but what I want to do is if it finds an error, It attaches a MC in the library to an empty MC created before the movie was loaded. But I want it all to be dynamic and I can't position the error msg MC in the right spot because I can't reference it w/a variable. I've tried eval() but it didn't work.


ActionScript Code:
// Checks for Error
    mcLoader.onLoadError = function(movClip, errorCode) { // Constructor
        var errLevel = level + 300;
        var msgName = "errorMsg" + prefix;
        // Checks type of error
        if (errorCode == "URLNotFound") {
            mcErrorLoad.attachMovie("txtErrorNoFile", msgName, errLevel)
        } else if (errorCode == "LoadNeverCompleted") {
            mcErrorLoad.attachMovie("txtErrorNoLoad", msgName, errLevel)
        }
        // Positions MC in center of designated area.
        mcErrorLoad.msgName._x = (movieWidth * .5) - (mcErrorLoad.msgName._width / 2) + xPos;
        mcErrorLoad.msgName._y = (movieWidth * .5) - (mcErrorLoad.msgName._height / 2) + yPos - 4;
    if (prefix == "nav") {
        LoadClip("secnav", 30, 0, 273);
        }
    if (prefix == "secnav") {
        LoadClip("sechome", 40, 149, 273);
        }
    if (prefix == "sechome") {
        LoadClip("home", 20, 0, 27);
        }
    }
    // End of Errors
 


This is how the MCL fires:

ActionScript Code:
//Use a loop to search through the File Array to find the appropriate file
    for (var i=1; i<_level0.listFile.length; i++) {
        if (prefix == _level0.listFile[i]["prefix"]) {
            var clipFileName = _level0.listFile[i]["file"];
            var documentName = _level0.listFile[i]["dName"];
            var movieWidth = _level0.listFile[i]["mWidth"];
            var movieHeight = _level0.listFile[i]["mHeight"];
        }
    }
    // Load Nav SWF
    mcLoader.loadClip(clipFileName, level);


It creates the 4 error MC's but I cant position them with:
mcErrorLoad.msgName._x = (movieWidth * .5) - (mcErrorLoad.msgName._width / 2) + xPos;

mcErrorLoad.msgName._y = (movieWidth * .5) - (mcErrorLoad.msgName._height / 2) + yPos - 4;

Because it won't point to the MC using the variable but if I use the actual name, it does fine.

As I've said, I cant get eval() to work with this. I really hate to repeat posts, but I'm at a loss.

How Do I Convert A (String + Variable)'s Value To An Object?
I hope I can explain this correctly.

How do I convert a (String + variable)'s value to an object?
This is an abstract of the code below:

Code:
createTextField(String("tf"+i),i,"tf"+j._x + "tf"+j._width,0,50,17);

I have tried String(); so that I can convert the value to an object but I don't think String is correct here. I have also tried Boolean(); but to no avail.

Can anyone please help me with this. Your help is graetly appreciated. Thank you.


Code:
for (i=1;i<3;i++) {
if (i==1) {
createTextField("tf1",1,391,0,50,17);
tf1.autoSize = "left";
tf1.selectable=false;
tf1.text = t1;
tf1.setTextFormat(myformat);
} else {
j=i-1;
createTextField(String("tf"+i),i,"tf"+j._x + "tf"+j._width,0,50,17);
this["tf"+i].autoSize = "left";
this["tf"+i].selectable=false;
this["tf"+i].text = this["t"+i];
this["tf"+i].setTextFormat(myformat);
//trace(tf+i._x);
//trace(this["tf"+j]._x + this["tf"+j]._width);
}

}

Referencing Object Using Variable Syntax
I'm having trouble referencing an object using a variable in Flash MX.
In this example, I'm dynamically loading jpegs and need to test that they have finished loading.
The img var contains the url of the image to load.


On the first frame:

for(i=0; i<number_of_images; i++)
{
//duplicate the holder
duplicateMovieClip(my_movie.holder, i, i);

//create reference for the img to load
img_to_load = "my_movie.holder." + i;

//load image into the duplicated movie
img_to_load.loadMovie(img_url);
}

On another frame:
if(img_to_load.getBytesTotal() >= img_to_load.getBytesLoaded() )
{
//image has loaded
}else{
//image still loading
}


My problem is that img_to_load is a variable that returns a string and not an object - what do I need to do?

Thanks in advance

How To Create A Global Variable From Within An Object?
I have an object on my stage, and within that object I have embedded some ActionScript. It's simple, something like this:

number = 5;

It works fine within that scene, but when I go to any other scene, I can no longer reference that variable. It comes up as "undefined."

How do I create a variable within that object that I can access from anywhere within my movie?

Using A Variable As A Field Name For A Shared Object
Hi,

Does anybody know of a way to use a variable as the field name for a shared object?
I am trying to save data to a shared object that is indexed to a number. Ideally I would like the following to work

sharedobject.data.varname = "data string"

I can create this manually as in

sharedobject.data.datastring1 = "data string"
sharedobject.data.datastring2 = "data string"

etc.

As I don't know the number of times data will be saved ahead of time, I cannot go the manual route. Not to mention doing it manually would be very inefficient.

I have tried a few things but nothing seems to work.

Any ideas?

TIA,

Colin

Please Help - Variable Object Property Names
I need to create variable object property names for use with the data grid component.

This works:

data = new Object();
data.some_name = "the data";

But this does not:

data = new Object();
colName = "some_name";
data[colName] = "the data";

Can anyone help me? Can object property names be variable?
Thanks.

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