all groups > flash actionscript > august 2005 >
You're in the

flash actionscript

group:

Dynamically Assigning an image to contentPath


Dynamically Assigning an image to contentPath The_Narrator_2002
8/5/2005 9:08:18 PM
flash actionscript:
Hi There, just looking for some help. I am trying to load an image into loader
by using an external text file. I understand how to hardcode it using the
component imspector but I want to be able to drop a variable in there that
loads from an external text file. Is it just something simple that I am missing?

Is it possible to just load the variable from the text file in the first
frame and then drop that variable name into the contnetPath or is the a whole
ton more of actionscript that I need to be doing? TIA for any suggestions..
this one has me stumped.

I am using Flash MX 2004 professional and am of course using actionscript 2
with flash player 7.
Re: Dynamically Assigning an image to contentPath kglad
8/6/2005 12:18:46 AM
the most common problem would be failing to ensure the data are loaded before
using. you should probably be using an onData() or onLoadInit() handler to
ensure the data are loaded and within that handler execute your load image code.
Re: Dynamically Assigning an image to contentPath The_Narrator_2002
8/8/2005 12:00:00 AM
Thanks for the response. Not quite sure I understand... so far I have a frame
in the beginning of the clip that loads the textfile and it's variables in:

loadVariablesNum("textfile.txt", 0);

The text file has all my variables defined such as text that goes in the clip
as well as links for the some dynamically assigned butttons. The buttons
simply use the actionscript below to load the link varibles from the same text
file:

on (release) {getURL(_root.link1);

}

I currently have images loading in externally by using the loader component
that has the hardcoded contentPath. I am looking to somehow define that
contentPath from the text file instead of hard coding it.

So is there any way for me to define dynamic images in the text file and have
the loader pull from that variable? Basically I want people to be able to
simply change the text file and have images, copy and links load in to the clip
from it. Does that make any sense?
Re: Dynamically Assigning an image to contentPath kglad
8/8/2005 12:00:00 AM
Re: Dynamically Assigning an image to contentPath The_Narrator_2002
8/8/2005 12:00:00 AM
Excellent.. how do I do that though?.. do I just drop the variable name in the
text file in that field? Right now it's just the URL of the image in there..
so in order to change it I have to overwrite the same image. I am looking to be
able to change the image name on the fly. Could you possibly give me an example
of what I would type in that field if the image varible in the text file was
named "dimage"? Thanks!
Re: Dynamically Assigning an image to contentPath bUgStAtIoN
8/8/2005 12:00:00 AM
Re: Dynamically Assigning an image to contentPath The_Narrator_2002
8/8/2005 12:00:00 AM
OK... the FLA and text file are linked here:
http://www.toyotacentertix.com/dynamicimage.zip. The idea is that in the text
file I have variables named newimage1,newimage2 and newimage3. I want to be
able to change these and have them load into Ad1, Ad2 and Ad3 symbols
dynamically in the movie. Currently I have the full link written into each ad
symbol via contentPath. Thanks again!
http://www.toyotacentertix.com/dynamicimage.zip
Re: Dynamically Assigning an image to contentPath kglad
8/9/2005 12:00:00 AM
you don't need to type anything in properties panel. assign the contentPath
property using actionscript:

dataHolder.loadVariables("myTextFile.txt");
dataHolder.onData=function(){
yourLoader.contentPath=this.myURL; // where your myTextFile.txt contains:
&myURL=path.fileName&
}
Re: Dynamically Assigning an image to contentPath The_Narrator_2002
8/16/2005 4:30:01 PM
OK.. so I think I am starting to understand this

So if my text file was called links.txt and it sat in root with the flash file
and my image path in the text file looked like this:
&myURL=http://www.website.com/image1.jpg& and my Loader instance was named
"story1"
Then my action script would look like this below and sit in my first frame of
the movie right?

dataHolder.loadVariables("links.txt");
dataHolder.onData=function(){
story1.contentPath=this.myURL;
}

Sorry but I feel like I am so clse and I am just missing something minor.
Re: Dynamically Assigning an image to contentPath kglad
8/17/2005 12:00:00 AM
yes, that should work as long as you don't execute the story1.load() until
story1.contentPath is defined:

dataHolder.loadVariables("links.txt");
dataHolder.onData=function(){
story1.contentPath=this.myURL;
story1.load();
}
AddThis Social Bookmark Button