PDA

View Full Version : Load image in a TextArea



shubs6
January 7th, 2008, 07:03 AM
Hi,
I'm trying to add an image at runtime to my textArea like this. But when i run the app, the textarea shows blank. Please help friends......


<mx:Script>
<![CDATA[
public function addImage(event:Event) : void
{
//file vim.png is present both in Project folder and in the src folder of the Project
txtarea.htmlText = "<img src='vim.png'>";
// txtarea.htmlText = "<img src=\"vim.png\">";

}
]]>
</mx:Script>
<mx:TextArea x="103" y="70" height="216" width="291" editable="false" wordWrap="true"
id="txtarea" creationComplete="addImage(event)"/>


I checked
http://www.actionscript.org/resources/articles/122/1/Loading-Images-Via-XML-into-Flash-MX-2004/Page1.html
but didnt help my cause.
Alternatively I tried following too. but this too didnt help


<mx:Script>
<![CDATA[
import mx.controls.Image;
import flash.net.URLLoaderDataFormat;
public function addImage(event:Event) : void
{
var loader : URLLoader = new URLLoader();
var request : URLRequest = new URLRequest("vim.png");
loader.load(request);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE , showImage);
}
public function showImage(event : Event) : void
{
var loader : URLLoader = URLLoader(event.target);
txtarea.htmlText = loader.data;
}
]]>
</mx:Script>
<mx:TextArea x="103" y="70" height="216" width="291" editable="false" wordWrap="true"
id="txtarea" creationComplete="addImage(event)"/>

GrndMasterFlash
January 7th, 2008, 10:22 AM
try a trace after you add the image to your htmlText and see what the function is doing, then post the trace here it looks right to me so there might me a small little error hiding, gotta trace this one out i think

SpaceHunter
January 7th, 2008, 11:56 AM
I can load the image in the Textarea successfully. I think you may have a problem with your image path. Does 'vim.png' exist in your root directory? Make sure the path to your image is correct.

shubs6
January 8th, 2008, 05:02 AM
I tried trace and some other tricks too. But haven't been successful. its a small thing but not being able to work it out... :puzzle:
Any ideas friends?

mjmdotorg
January 8th, 2008, 05:32 AM
Try to look around and you will find the correct solution

shubs6
January 8th, 2008, 07:46 AM
I was looking in https://bugs.adobe.com/ and from some bugs there I found that this is perhaps a bug in TextArea. Can you suggest an alternate container/control where I can show text and image nicely formatted together?

shubs6
January 8th, 2008, 07:47 AM
I'm using Moxie 3 beta 3 build 190133

shubs6
January 9th, 2008, 11:42 PM
Got the workaround of this problem. Use Component <mx:HTML> rather than <mx:TextArea>. There are some issues with textArea when it is used with AIR in Flex Projects.
Check out https://bugs.adobe.com/jira/browse/SDK-14238?rc=1 for details