views:

1993

answers:

3

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.
A: 

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

sthg
Can you be a bit more specific how you would do that? I'm not explicitly importing the image (and I don't want to if I can avoid it). I'm trying to reach into the incoming html and find any images in there and apply smoothing to them.
sprugman
+1  A: 

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);
David Hanak
I tried that, but I'm not surprised it didn't work -- the error is being thrown on the line that sets up the event handler, so it's never getting to that line of code.
sprugman
@Sprugman, what?! The error refers to an inexistent method/property "content" so it's definitely this line "Bitmap(event.target.content).smoothing = true;" that is failing. The registration of the event, as long as it sends an event:Event, should work fine in any case. But I'm 3 months late to the party, so the important thing is that you've got it solved.... :)
Yar
+1  A: 

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.