Hello,

I have figured out how to work around my problem, but I do wonder why
one of the following methods works, and the other doesn't. I would be
grateful if someone could explain the error in the failing method.

The code is pasted below (Below the line of dashes) in it's entirety,
and is commented as to which works and which doesn't.

The image referenced in this case is a 32x32 pixel png file on my
local system. I am attempting to display the image "on" a text area.

Using the default example from the flex documentation to embed an
image, I cannot get the image to show up when added to the text area's
display list, but it does show just fine when added to the root
display list. I also added the image to the textArea using
addChildAt(txtIcon, txtArea.numChildren) with no change in effect.

The second method works just fine. I imagine that the problem has
something to do with applying the image as a byte array to
image.source, but I wonder why exactly? Is this a bug?

Thanks in advance,

--Aaron

------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute">
        
<!--Works-->
<mx:Image id="txtIcon" source="@Embed(source='c:/icon.png')"/>

<mx:TextArea id="txtArea" width="400" height="200" click="addImage()"/>

<mx:Script>
    <![CDATA[
        import mx.controls.Image;
        import mx.core.BitmapAsset;
        
        // Doesn't work
        [Embed(source="c:/icon.png")]
        [Bindable]
        public var imgCls:Class;

        public function addImage():void
        {
            // Doesn't work
            var loadedImg:Image = new Image();
            loadedImg.source =  new imgCls() as BitmapAsset;

            loadedImg.x = 10;
            loadedImg.y = 10;
            txtArea.addChild(loadedImg);

            // Note: While the above doesn't work, adding the 
            // image to the root display list does work:
            //addChild(loadedImg);

            // Works
            txtIcon.x = 50;
            txtIcon.y = 10;
            txtArea.addChild(txtIcon);
        }
    ]]>
</mx:Script>

</mx:Application>


Reply via email to