开发者

Using img tag in an AS3 TextField without width and height attributes

I'm attempting to load HTML from t开发者_如何学运维he Shopify blog API into a TextField in Flash. The problem is that Shopify doesn't add width and height attributes to images that are in the blog posts. When I load these into Flash, the width and height of the image is ignored and the height of the TextField is incorrectl, which screws up my scrollbar among other things.

Is there any way to read the width and height of the images as they are loaded? I could possibly do this with PHP before it gets to Flash, but I'm not sure how.


Not sure about your original question about getting the image info in flash, but in PHP it wouldn't be much trouble, although it would slow down the process down somewhat.

Step 1: Setup a PHP proxy, which you call from your flash.

Step 2: In your PHP proxy, after grabbing the HTML, loop through all the img-tags. (You can do this easily, with e.g. PHP Simple HTML DOM)

Step 3: While looping, if the image dimensions are missing from the img-tag, download the image, check the image size and update the tag. (Also easy using PHP Simple HTML DOM)

Step 4: Echo the updated HTML to your flash movie.


If you use the BitmapData class you can get access to the width and height of images, along with other useful properties and methods.


if you load the image data (URLLoader in FlashPlayer or FileStream in AIR) (FileStream would lets you do it synchronously) with some effort you can parse the width and height of the image from the file HEADER synchronously.

if you want to display the image from the image data, throw it at loader.loadBytes for Adobe to decode it for you. sounds like you want it to show up in the htmlText though.

if you can manage to take a synchronous path to get all this data, your textfield can take into account the image height before the next frame so it won't look jittery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜