Hi gurus,

I use the following code to display a text field with <img> tag inside. The 
image source is OK(the Image object works), but no picture was displayed in the 
text field. And one more issue is, if no chars before the <img> tag in 
htmlText, even the data of image was not loaded.

Anybody experienced similar issue? Thanks a lot.

=============see my code below==========================

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
creationComplete="onCreation(event)" layout="vertical">
<mx:Script>
        <![CDATA[
                import mx.controls.Image;
                import mx.core.UITextField;
                import mx.core.FlexTextField;
                private function onCreation(event:Event):void
                {
                        
                         var img:Image = new Image();
                        img.source = "images/orgunit.png";
                        //this.addChild(img); 
                        
                        var text:UITextField = new UITextField();
                        
                        // no chars before img tag, then getImageReference 
returns null
                        //text.htmlText = "<img src='images/orgunit.png' 
id='testImage'>";
                        // a blank char before img tag, getImageReference 
returns a Loader object and data is loaded well but nothing displayed.
                        text.htmlText = " <img src='images/orgunit.png' 
id='testImage'>";
                        text.height = 50;
                        text.width = 100;
                        text.multiline = true;
                        
                        this.addChild(text);
                        
                        var ir:Object = text.getImageReference("testImage");
                        
                        var il:Loader = ir as Loader;
                        il.contentLoaderInfo.addEventListener(Event.COMPLETE, 
onLoadPicComplete);
                        
il.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
                        
il.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
                }
                
                private function onError(event:IOErrorEvent):void
                {
                        trace(event.text);
                }
                
                private function onProgress(event:ProgressEvent):void
                {
                        trace(event.bytesLoaded);
                }
                
                private function onLoadPicComplete(event:Event):void
                {
                        trace(event);
                }
        ]]>
</mx:Script>
</mx:Application>


Reply via email to