Skip to main content
Mar 27, 2009 3:22 PM UTC
Answered

event listener on inline graphic

Hi

Is there a way to add an event listener to an inline graphic.
I cant seem to find much... or any help concerning this in the forums.

I remember reading a post about this a while back where someone wanted to add a doubble click to an inline graphic without success. Has that been resolved?

Im desperate to get this working and any help would be much appreciated

Thank you
This topic is closed to new replies. Start a new post to keep the conversation going.
rdermerCorrect answer
Inspiring
Apr 1, 2009 5:25 PM UTC
My initial thought was to listen for the "ready" events and build a dictionary mapping graphics to the owning ILG element. You can make the keys of a Dictionary weak so they don't leak.

For #3 there is no direct way of finding an ILG based on source other than walking the TextFlow. To do that I'd write something like textFlow.getFirstLeaf() and then loop while leaf.getNextLeaf()

ILGs can be modified either directly using the APIs or via operations. If you directly modify the ILG you are responsible for calling updateAllContainers.

Richard

9 replies

Inspiring
Apr 2, 2009 4:20 PM UTC
The main advantage of dictionary is that the keys can be made into weak references. That way if you delete the TextFlow the dictionary won't lock the graphics and ILG elements into memory.

The ins and outs of how the MouseEvent targets are defined is internal to FlashPlayer.

Richard
Translate
rdermerCorrect answer
Inspiring
Apr 1, 2009 5:25 PM UTC
My initial thought was to listen for the "ready" events and build a dictionary mapping graphics to the owning ILG element. You can make the keys of a Dictionary weak so they don't leak.

For #3 there is no direct way of finding an ILG based on source other than walking the TextFlow. To do that I'd write something like textFlow.getFirstLeaf() and then loop while leaf.getNextLeaf()

ILGs can be modified either directly using the APIs or via operations. If you directly modify the ILG you are responsible for calling updateAllContainers.

Richard
Translate
Apr 2, 2009 1:51 PM UTC
Thats perfect. Thank you.

I started doing something similar using Object instead of Dictionary. I have never used the Dictionary class.

ie theObject[count] = ILGElement
I then access the LIGElement through that Object.

Should I be using the Dictionary Class as a better way of doing this. ie What is the advantage of using the Dictionary class.

Thanks again for your help

I dont know if this is anything but I noticed that if I load an image as an ILG and add the event listener to the graphic property. the target when using "e.target.name" is correct but if I load an external swf as an ILG, the e.target.name in not correct. its as though the target is an object inside the swf. e.target.parent.patent.name in this case traces the correct name.

Thanks

Translate
Inspiring
Mar 31, 2009 12:55 AM UTC
Check StatusChangeEvent.status for "ready" and only upate in then. The event is dispatched for every status change.

When you click the graphic you'll have to figure out some way to map back to the InlineGraphicElement. The eventMirror approach may be useful for that. Either that or build a dictionary of mappings.
Translate
Apr 1, 2009 6:20 AM UTC
HI

Thanks again for the reply. Check StatusChangeEvent.status for "ready" works perfectly.

Sorry to ask more questions on this topic but I cant find documentation or info anywhere else. If you could give me a link I would be happy to go that route...

I added an event listener to the inline graphic and gave it a name as follows:
ILG.graphic.name = LIG.source.toString();
ILG.graphic.addEventListener(MouseEvent.MOUSE_OVER, ILGhandeler);

then when I trace the target I get //instance23
eg trace(e.target.name) //instance23
but if I do the following I get the source that im looking for:
trace(e.target.parent.parent.name) // path/to/graphic.

1) Is what IM doing good practise?
2) can I add the source to something other than the .name //eg ILG.graphic.theurl = ILG.source.toString();
3) Is there a way to target and replace or update an ILGElement just by knowing its source.
ie (replace or update) ILGElement where LIGElement.source == "theurl"

Help with this will be awesome. Thank you for your patience




Translate
Participant
Mar 30, 2009 10:21 AM UTC
Inspiring
Mar 27, 2009 4:19 PM UTC
There's two ways I can suggest to to go about this. I haven't tried any of these out recently.

One is to attach an event listener to the graphic itself by accessing the ILG (InlineGraphicElement) graphic property. If the graphic is being downloaded listen on the TextFlow for inlineGraphicStatusChanged events. Attach the listener when the status is "ready".

The other is to call ILG.getEventMirror and add the listener there. This API was recently added.

Hope that helps

Richard
Translate
Mar 27, 2009 5:52 PM UTC
Hi rdermer

Thanks for the reply. I will give it a go and get back with my findings.
Translate