Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display image from variable name 1

Status
Not open for further replies.

bbrb1966

Technical User
Dec 10, 2001
16
NL
Hi All,


This is probatly very simple, but browsing through the forum hasn't provided me with an answer.

How can I display an image by it's name ?

I have a CFM-file with the outcome:
&something=10&somethingelse=hello&image=somepic.jpg

In actionscript I use:
loadVariablesNum ("object.cfm", 0, "POST");
to load the variables, and that works, if I use Dynamic text and enter the variable names.

In addition I would like the picture to be displayed in a new movie, if I use: objimage.loadMovie("somepic.jpg"); it works fine, but when I use: objimage.loadMovie(image); it doesn't seem to use the variable image from the CFM-file.

Can anyone please tell me what I doing wrong ?

Regards, Ron

 
The variables are in the root level of the movie so try changing your addressing.

Code:
objimage.loadMovie(_root.image);

Looks right otherwise. If you need more help we may need more info on how your movie is constructed.

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Hi pix8r,


Thanks for your reaction but sorry to say, it doesn't work.

You asked me about the movie, it's just a blank and the name is objimage.

The thing i don't get is that if I change my code from:
loadVariablesNum ("object.cfm", 0, "POST");
objimage.loadMovie(image);


to:
loadVariablesNum ("object.cfm", 0, "POST");
image = "somepic.jpg"
objimage.loadMovie(image);


that it works, the picture goes into the movie, so it seems that the parameters are not read \at this time, however I have an dynamic text field where I show 'image' and there it shows the 'somepic.jpg' (with the first code that is)

Any suggestions ?

Regards, Ronald

 
Just to make sure that I understand...

You have a blank Movie Clip in your main timeline with the instance name of "objimage"?

When loading the variables your dynamic text box (variable "image") displays the file name, but the image will not load into the movie clip.

Is that about right?

Wow JT that almost looked like you knew what you were doing!
 
Hi pixl8r,

The FLA is exactly as you discribe, it's just one frame, i'm familiar with ColdFusion but Flash is new to me.

I put the FLA on
Thanx in advance, Ronald
 
A few things I notice.

1. The Case of your variable names is not the same. (CFimage and cfimage). This shouldn't matter but I thought I would mention it.

2. I think your problem is that your movie is getting loaded before the variables are all in. In other words the objimage.loadMovie() action is happening before the cfimage variable is getting into the movie.

3. You have no images in the directory that had the fla and cfm pages.

The solution is to use the loadVars object instead of loadVariablesNum().

I think this will fix your problem. Change your AS as follows:

Code:
myVars = new LoadVars();
myVars.onLoad = function(success){
	if (success){
		_root.CFtype = myVars.CFtype;
		_root.CFPrice = myVars.CFprice;
		_root.CFimage = myVars.CFimage;
		_root.CFsize = myVars.CFsize;
		_root.CFtype = myVars.CFtype;
		objimage.loadMovie("imagesDirecotoryorURLofImage/"+ myVars.CFimage);
	}else{
		trace("The variables didn't load");
	}
}
myVars.load("[URL unfurl="true"]http://62.212.76.220/ron/object.cfm");[/URL]

Using the loadVars() object allows you to check to see if the data has loaded before you try to act on it (onLoad).

Notice the syntax for loading the image. Replace the "imagesDirecotoryorURLofImage/" with the web directory your images are in.

I think that will fix you up. Let me know if it works ok.

Wow JT that almost looked like you knew what you were doing!
 
Thanx pixl8r

That did it, so it must be what you mentioned the image isn't loaded when then movie starts.

To your remarks, I knew that capitals didn't do it, it because of the testing, normally I would watch it. The image itself I didn't upload, just the FLA fyi, I'm testing locally

One small thing, the picture is larger as the movie, is there a simple setting that will resize (like i use width=50 in html). I'll look for this in the forum aswell.


Thanx again for your time, I appreciate it bigtime, Ronald


 
No problem. Glad it helped. I work for stars :).

You can change the properties of the objimage clip after you have loaded the image.

Code:
objimage._height = 100;
objimage._width - 100;

I would recommend making thumbnails for the images if they are that much larger than the size in the movie. It will just cost you more in resources and bandwidth to resize them in the movie at runtime.

Wow JT that almost looked like you knew what you were doing!
 
Hi pixl8r,

Sorry to bother again, but the width and height don't seem to work, Í've tried several places to insert but the picture disappers again (I assumed that the minus is a typo) If I use cfimage instead of objimage (just testing) than the image appears in original size.

In the original html-pages I allready use thumbnails, but they are 200x240 so I needed this 'resize' function.

Regards, Ronald

 
Well I was trying to give you something a little more accurate than this but I know this will work.

Code:
objimage._xscale = 50;
objimage._yscale = 50;

This is in percentages so you will have to tweek it to work for you.

The _width and _height thing goes back to Flash 3 but it was still in the dictionary so I thought it migh work. Obviously incorrectly. :)

Have fun!

Wow JT that almost looked like you knew what you were doing!
 
Thanx pixl8r

That totally works for me !

Regards, Ronald
 
bbrb1966, please give pixl8r his star (press the link next to the purple star at the bottom of his post). This way people can easily see that a solution was found for this issue.
Thanks,
Philip

Philip Keiter
Senior Flash Software Developer
Sphyrras
 
oh wait, i just realized i can do it for you. doh!

Philip Keiter
Senior Flash Software Developer
Sphyrras
 
I just found this post and I am having the exact same issue in terms of my image not showing up. I used the code here and it still doesn't work. BTW- I am trying to load this from a php file (and MYSQL) which gives the proper variables in this form:"&returnVal=Jan&returnVal2=Berge&returnVal3=jet.jpg" Here is the code:
Code:
stop();
//=================================
//	Begin
//=================================
path= "[URL unfurl="true"]http://localhost/flashtest/";[/URL]   
lvOut = new LoadVars();            
lvIn = new LoadVars();           
lvIn.onLoad = function (success) {
        if(success){
               output.htmlText =  lvIn.returnVal;
	       output2.htmlText = lvIn.returnVal2;
	       output3.text = lvIn.returnVal3;
	       _root.output3 = lvIn.returnVal3;
	_root.createEmptyMovieClip("container",7);
        container.loadMovie(_root.output3);
        container._x = 400;
        container._y = 0;
_root.onMouseDown = function () {
	startDrag ("container",false) ;
}
_root.onMouseUp = function () {
	stopDrag () ;
}

        }else{
                output.text = "fail";
		output2.text = "fail";
		output3.text = "fail";
        }
}
//=================================
//	Button Fetch Vars
//=================================
myBtn.onRelease = function(){
        lvOut.yes = yes.text;
        lvOut.sendAndLoad(path + "test.php", lvIn, "POST");
};

Rninja

smlogo.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top