2
votes

I've got a movie clip on the stage that's rotated 10°, with a dynamic text box inside. I'm loading some text, with an embedded image into it thus:

(Using 1st frame AS3 for now, eventually this will go in a class.)

var txt:String = '<img src="foo.gif" id="myImg1" /><p>Lorem ipsum</p>';

my_mc.txtBox.htmlText = txt;

Which works fine. The text gets placed, and even wraps around the image nicely. Problem is, the image looks horrible. I found the Bitmap.smoothing property, but can't seem to access the image to set the property. I'm trying this code:

var img:DisplayObject = my_mc.txtBox.getImageReference('myImg1');
if (typeof(img) != 'undefined') {
    img.contentLoaderInfo.addEventListener(Event.COMPLETE, onHtmlImageLoaded);
}

function onHtmlImageLoaded(event:Event):void{
    event.target.removeEventListener(Event.COMPLETE, onHtmlImageLoaded);
    Bitmap(event.target.content).smoothing = true;  
}  

the 'img.contentLoaderInfo...' line throws this error, though:

1119: Access of possibly undefined property content through 
a reference with static type flash.display:DisplayObject.
3
For some unknown reason I got navigated here, so let me make this seemingly irrelevant comment: you say "later I'll make it a class" but this is not a good way to work. Who cares? Well, if you made it a class FIRST, your IDE (FlashDeveloper or FlexBuilder, YES, even for 100% Flash IDE work) would, through autocomplete, let you know (if you do the unecessary casts) what is acceptable for that event.target.content line. Note my comment below on David's answer... Anyway, I'm 3 months late, so I'll just disappear :)Dan Rosenstark

3 Answers

2
votes

try this:

var img:Loader = Loader( tx.getImageReference('proceso') );
img.contentLoaderInfo.addEventListener(Event.COMPLETE, onHtmlImageLoaded);

function onHtmlImageLoaded(event:Event):void{
    event.target.removeEventListener(Event.COMPLETE, onHtmlImageLoaded);
    Bitmap(event.target.content).smoothing = true;      
}

it's work.

1
votes

I think you're simply missing a cast to Loader in your event handler:

Bitmap(Loader(event.target).content).smoothing = true;     

Edit: Do the same when registering the event handler:

 Loader(img).contentLoaderInfo.addEventListener(Event.COMPLETE, onHtmlImageLoaded);
0
votes

I would try using the BitmapData Class for the image, and apply smoothing to that.