Loading Images in a cfform
26 comments Posted by: NahuelI made an example that shows how to load different types of images into a flash form.
In a cfform, it is possible to load gif, jpg, png, and swf.
Basically, there are two types of methods to load an image inside a cfform: at compile time and at runtime. cfinput embeds the images in the cfform at compile time, allowing more variety of image types (png and gif) that are not directly supported by the flash player. cfformitem and other controls such as textarea load the images at run time, so they are limited to the types supported by the flash player, accepting only jpg and swf .
Note that cfinput type="image" will put the image inside a button, so in the example, the first four images have borders and rollover states.
There seems to be a bug when loading jpg images in Firefox when the cfformitem only contains the image. Although it only happens sometimes, the image does not load. One way to fix the problem is adding some text in the formitem before the image, or other tag, such as a <p>.
Here is the code:
<cfform name="myform" height="300" width="300" format="Flash">
<cfformgroup type="hbox">
<cfinput type="image" height="27" src="images/home_bg.gif" name="gif" onClick="" width="104">
<cfinput type="image" height="27" src="images/home_bg.jpg" name="jpg" onClick="" width="104">
<cfinput type="image" height="27" src="images/home_bg.png" name="png" onClick="" width="104">
<cfinput type="image" height="27" src="images/home.swf" name="swf" onClick="" width="104">
<cfformitem type="html" height="35" width="104"><p><img src="images/home_bg.jpg"/></p></cfformitem>
<cfformitem type="html" height="35" width="104"><p><img src="images/home.swf"/></p></cfformitem>
</cfformgroup>
</cfform>You can also load a jpg with css but that goes to another post :)
View the example
Download the code
26 Comments so far
Write yoursI think there is no <cfformitem type=page>, do you mean cfformgroup?
You can do something like including a cfformitem inside a cfformgroup:
< cfformgroup type="page"><cfformitem type="html"></cfformitem ></cfformgroup>
So, like this:
<cfformgroup type="page" label="!!IMAGE GOES HERE!! This is Page One's Label">
Any ideas on that?
Thanks!
<cfquery datasource="crafts" name="random_images" maxrows="4">
SELECT product_id, product_name, product_image3 FROM products
</cfquery>
<cfset MyList=ValueList(random_images.product_image3,',')>
<cfset path_1="http://localhost:8500/armenianrugmasters/images/#ListGetAt(MyList, 1)#">
<cfset path_2="http://localhost:8500/armenianrugmasters/images/#ListGetAt(MyList, 2)#">
<cfset path_3="http://localhost:8500/armenianrugmasters/images/#ListGetAt(MyList, 3)#">
<cfset path_4="http://localhost:8500/armenianrugmasters/images/#ListGetAt(MyList, 4)#">
<cfform method="get" format="flash" >
<cfformgroup type="horizontal" height="200" width="700" visible="yes" enabled="yes" >
<div align="center">
<cfinput type="image" name="image1" src="#path_1#" width="150" height="170"/>
<cfinput type="image" name="image2" src="#path_2#" width="150" height="170"/>
<cfinput type="image" name="image3" src="#path_3#" width="150" height="170"/>
<cfinput type="image" name="image4" src="#path_4#" width="150" height="170"/>
</div>
</cfformgroup>
</cfform>
This works. If i was trying to use something like:
src="random_images.product_image3" it doesnt.
May be this can be helpful to anybody.
If you view your example now do those last to images load for you? because in the code I see 6 images but only the for cfinput images load for me.
I assume this used to work but I cant seem to get it to. Does the example still work for you?
Sorround your image with paragraph tags <p><img></p>
That should work around the problem. I believe it is a flash bug.
Thanks so much. I have been banging my head on the wall. my forhead thanks you :)
Any suggestions?
Try to adjust the values on the cfformitem too.
Thanks!
1) image must be within its own <cfformitem> tag (any text within this tag seems to make the image not display)
2)<cfformitem> must have height and width attributes added otherwise the image is cut off
3) image tag must be within <p> </p>
I am trying to dynamically load up images, while I figured out a way to show the initial images at load time by executing a query and getting the initial image filenames for the images. The tough part is using a dropdown to select another batch of images, and using the flash remoter to call those images. When the flash remoter builds the new query set, I am not sure how to use the resulting queryset on my application, because the image display portion of my application is not an object to put the results against. If it was a grid it would not be a problem, but a grid does not show the images the way I want to. Please somebody help me out with this.
i have a slideshow.swf within an cfformitem and want to trigger functions in the external swf.
i.e myGallery.loadImage(1);
regards
herbert
Only the first image displays.
<cfformgroup type="horizontal">
<cfformitem type="html" height="50" width="400">
<p><img src="http://yoda.wvu.edu/esli/images/d01.jpg" width="10">
<img src="http://yoda.wvu.edu/esli/images/d02.jpg" width="10">
<img src="http://yoda.wvu.edu/esli/images/d03.jpg" width="10">
<p><img src="http://yoda.wvu.edu/esli/images/d04.jpg" width="10"></p>
</cfformitem>
</cfformgroup>
I just came across this article about loading gif and png at runtime. http://www.informit.com/guides/content.asp?g=flash&seqNum=343&rl=1
So maybe it is possible to load gif and png dynamically in a cfformitem somehow??
Very frustrating, can anyone help?
Thanks!
<cfformitem type="html" height="50" width="92"><p><img src="images/gs.gif"/></p></cfformitem>
Your main problem is that you cannot load gif using the image tag in Flash. You need to use a jpg instead. See the post example on how to load gif or png. Also, you don't need to escape your <p> elements.
Hope that helps
Here's what I've tried so far, the image displays, but doesn't position.
#logo{
position: absolute;
top: 250px;
left: 660px;
z-index:2;
}
<div id="logo">
<cfformitem type="html" height="62" width="148"><p><img src="images/logo.jpg" alt="logo" name="logo" width="148" height="62"/></p></cfformitem>
</div>
Thanks!
Doesn't seem like posts are getting answered any more on this site but I was having the same problem you were relative to positioning images within a <cfformitem> tag. I found that by using the style attribute for the <cfformgroup> tag outside the <cfformitem> tag, you can position the image as you want. <cfformgroup style="marginLeft:660; marginTop:250;">. Give this a try and see, you may have to play with the numbers to get the image to position exactly as you want it to. Hope this helps.