View Full Version : TextField.htmlText - knowing when it's loaded
mdev
May 5th, 2009, 04:30 AM
Is there any way of knowing when htmlText with images is done loading? I'm using a scrollcomponent that sets the height before the image loading is done, meaning the whole content gets cut off too early. I was hoping that there would be a proper solution to this, but a workaround will do :)
IQAndreas
May 5th, 2009, 10:27 AM
Sadly, there doesn't seem to be any built in events for loaded images. Here are all of textField's dispatched events:
change (file:///C:/Programming/Flash/Docs/langref/flash/text/TextField.html#event:change)
Dispatched after a control value is modified, unlike the textInput event, which is dispatched before the value is modified.
link (file:///C:/Programming/Flash/Docs/langref/flash/text/TextField.html#event:link)
Dispatched when a user clicks a hyperlink in an HTML-enabled text field, where the URL begins with "event:".
scroll (file:///C:/Programming/Flash/Docs/langref/flash/text/TextField.html#event:scroll)
Dispatched by a TextField object after the user scrolls.
textInput (file:///C:/Programming/Flash/Docs/langref/flash/text/TextField.html#event:textInput)
Flash Player dispatches the textInput event when a user enters one or more characters of text.
There are more inherited events, but they don't have anything to do with content loaded inside of the textfield.
In addition, since textField does not extend DisplayObjectContainer, you can't loop through it's children and add listeners.
The only way I can think of (which seems a little farfetched and shaky) take advantage of the browser cache. Loop through the htmlText and search for all "img" tags. Then, for each image you find, load it in another loader (that's not even added to the stage). Add event listeners to this loader. Once the image is loaded in the loader, if the browser is caching downloaded images, chances are the same image in the textField is now loaded as well.
This might not work all the time, though, and might just make all the images download slower. :(
Also, I think the textField has a built in scrollcomponent already. Could you use this? Could you elaborate more what you want to do with scrollcomponent?
I'd do anything to find a workaround instead.
Krilnon
May 5th, 2009, 04:23 PM
You can use TextField#getImageReference (http://livedocs.adobe.com/flex/3/langref/flash/text/TextField.html#getImageReference()) to see whether or not a particular image has loaded. You could even attach listeners to the Loaders to see when each image completes loading. Since you're the one controlling the field's text content, you can also set or read the id attributes in all of the img tags, even if it means preprocessing the HTML in AS beforehand.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.