Skip to main content
Known Participant
July 13, 2009
Answered

Click handler for a span

  • July 13, 2009
  • 1 reply
  • 1629 views

Hi

I have a TextFlow which contains several span elements. (Each has an ID attribute.) When the user clicks on one of these spans, a pop up should appear whe the user can style the span.

I tried to assign a different event listener to each of the spans, but failed.

This brings the same result for both spans:

     element.tlf_internal::getEventMirror().addEventListener(MouseEvent.CLICK, regionClickHandler);


    public function regionClickHandler(evt:MouseEvent):void {
       Alert.show(evt.currentTarget.name.toString());
    }

Any ideas?

Tobi

This topic has been closed for replies.
Correct answer rdermer

I wasn't clear in my response.  computeSelectionIndex is a static tlf_internal method of SelectionManager.  Using an instance doesn't compile.

What I wrote above is literarly what you want to code.  Note you need these two lines as well

import flashx.textLayout.tlf_internal

use namespace  tlf_internal

FWIW EditManager is a subclass of SelectionManager.

Richard

1 reply

Adobe Employee
July 13, 2009

The target of the click is going to be a TextLIne.  From the TextLIne you'll need to map to the span that was clicked.  There's another tlf_internal method you can use as a helper.

var position:int = SelectionManager.computSelectionIndex(textFlow,evt.currentTarget,evt.target.evt.localX,evt.localY);

Use textFlow.findLeaf(position) to find the SpanElement that got the hit.  There may be issues at the first or last position in the span you'll have to resolve.

Hope that helps,

Richard

tobi3Author
Known Participant
July 15, 2009

Thanks for your reply Richard!

I have


    textFlow.interactionManager = editManager;

and no SelectionManager. (I assume only one of them can be used for a specific TextFlow instance).

It seems editManager.tlf_internal::computeSelectionIndex doesn't exist.

To all TLF implementers:

When a user clicks on a span in an editable TextFlow, my click handler should do something with that span (open a pop up containing a style editor for that span).

Is there a simple way to get the span that the user clicked on? It would be great if the event would have a method which returns that span.

Tobi

rdermerCorrect answer
Adobe Employee
July 15, 2009

I wasn't clear in my response.  computeSelectionIndex is a static tlf_internal method of SelectionManager.  Using an instance doesn't compile.

What I wrote above is literarly what you want to code.  Note you need these two lines as well

import flashx.textLayout.tlf_internal

use namespace  tlf_internal

FWIW EditManager is a subclass of SelectionManager.

Richard