Groups | Blog | Home
all groups > flash (macromedia) > june 2004 >

flash (macromedia) : path as variable



pwiop
6/29/2004 10:33:54 PM
Objective
What I am trying to achieve is this. 20 buttons (dynamically generated). Each
button displaying an external jpg which it loads into a picture viewer (this I
have achieved). On clicking each button information about each of the pictures
is loaded into a textfield from an external txt file (this I cannot achieve)

What I am Doing
I am loading 20 variables ?picinfo1? to ?picinfo20? from an external txt file
?myData.txt?

Each of the variables contains text such as ?my picture one? etc

I am dynamically generating buttons (within an mc) based on the number of
variables in the txt file ie. 20

I have a textfield component called ?textViewer?

If within the original button if I add the code _root.textViewer.text =
picinfo1, the textViewer is populated by information stored in that variable is
(obviously all the buttons display the information stored in that particular
variable)

Using the looping function that I have to dynamically create the buttons I
have a variable ?infoCount?

When I add the following code
_root.textViewer.text = ?_root.picinfo?+ infoCount - the text field just
displays _root.picinfo1 , _root.picinfo2, _root.picinfo3 etc but NOT the
information stored in those variables

It seems that it is being interpreted as a string NOT as a path. Is there any
way that I can make Flash recognise ?_root.picinfo?+ infoCount ? as a path NOT
a string

Sorry if this is a little confusing - I can upload a copy if anyone could be
bothered having a gander

paul

derobinson
7/2/2004 8:04:00 PM
When using variables as path names, you have to put sqaure brackets [ ] around
the variable. This also makes Flash assume a dot before the variable, so you
need to put the scope before the bracket. So something like this:

variable:String = myClip_mc;
_root[variable]....

will come out as "_root.myClip_mc"

Also note, the variable in the sqaure brackets can only be the clip name or
the scope, not both. So you can't set the variable to "scope.myClip_mc" and
expect "_root[variable]" to work. You can however put in two variables like so:

_root[scopeVar][variable]...

Hope that helps! Good luck!
/david


pwiop
7/4/2004 10:57:54 PM
DAvid, thanks a million

I have been pursuing this problem for a while now and unable to post here
where I normaly do due to the temp downtime the forums were having

Althouh folks on other forums were very helpful and came close (I can see this
comparing to your answer) it was never quite sorted so thank you once again

cheers

paul
AddThis Social Bookmark Button