Skip to main content
Known Participant
April 9, 2010
Question

Disable LinkElement interaction

  • April 9, 2010
  • 1 reply
  • 1303 views

Is there a global way to disable the LinkElement buttons across the entire TextFlow? The flow is not selectable or editable and I need to disable the links while I have another window open over the top of the flow.

This topic has been closed for replies.

1 reply

Adobe Employee
April 10, 2010

You can make your own link handler that you use in place of ours. Basically, if the url for the link starts with "event:", it will call an event handler instead of just bringing up the url in a browser window. Your handler can do navigateToURL if the links are enabled, and ignore it if links are disabled.

You may also want to change the way the links look when they are clicked on. You can do that by setting the linkFormat. You can make a single link format at the TextFlow level that controls the appearance of all the links in the flow.

Here's some sample code for the link handler:

package {

import flash.display.Sprite;

import flash.display.StageAlign;

import flash.display.StageScaleMode;

import flash.events.Event;

import flash.events.MouseEvent;

import flashx.textLayout.compose.StandardFlowComposer;

import flashx.textLayout.container.ContainerController;

import flashx.textLayout.edit.SelectionManager;

import flashx.textLayout.elements.FlowLeafElement;

import flashx.textLayout.elements.LinkElement;

import flashx.textLayout.elements.ParagraphElement;

import flashx.textLayout.elements.SpanElement;

import flashx.textLayout.elements.TextFlow;

import flashx.textLayout.events.DamageEvent;

import flashx.textLayout.events.FlowElementMouseEvent;

/** This example demonstrates custom event handling on a LinkElement.  In one case a click handler is added to a LinkElement.  In the other class the click handler is a event:EventName string.  */

public class CustomLinkEventHandler extends Sprite

{

private var textFlow:TextFlow;

private var pCustomClick:ParagraphElement;

private var pNamedEvent:ParagraphElement;

private function customClickHandler(e:FlowElementMouseEvent):void

{

// change the color of the first span of pCustomClick

textFlow.addEventListener(DamageEvent.DAMAGE,damageHandler);

var s:FlowLeafElement = pCustomClick.getFirstLeaf();

s.color = s.computedFormat.color == 0 ? 0xff0000 : 0;

}

public var doCompose:Boolean = false;

private function damageHandler(e:DamageEvent):void

{

textFlow.removeEventListener(DamageEvent.DAMAGE,damageHandler);

doCompose = true;

}

public function enterFrameHandler(e:Event):void

{

if (doCompose)

{

textFlow.flowComposer.updateAllControllers();

doCompose = false;

}

}

public function CustomLinkEventHandler()

{

stage.scaleMode = StageScaleMode.NO_SCALE;

stage.align = StageAlign.TOP_LEFT;

textFlow = new TextFlow();

textFlow.fontSize = 18;

textFlow.paragraphSpaceBefore = 12;

var p:ParagraphElement = new ParagraphElement();

var s:SpanElement = new SpanElement();

textFlow.addChild(p);

p.addChild(s);

s.text = "Demonstrate custom event handlers on LinkElement. \nThe first LinkElement has a custom click handler.";

pCustomClick = new ParagraphElement();

pCustomClick.fontSize = 24;

textFlow.addChild(pCustomClick);

s = new SpanElement();

s.text = "Custom Click: ";

pCustomClick.addChild(s);

var link:LinkElement = new LinkElement();

link.addEventListener(MouseEvent.CLICK,customClickHandler);

pCustomClick.addChild(link);

s = new SpanElement();

link.addChild(s);

s.text ="click me for a custom click event.";

textFlow.flowComposer.addController(new ContainerController(this, stage.stageWidth, stage.stageHeight));

textFlow.flowComposer.updateAllControllers();

textFlow.interactionManager = new SelectionManager();

addEventListener(Event.ENTER_FRAME, enterFrameHandler);

}

}

}

- robin

PoobeardAuthor
Known Participant
April 11, 2010

Sorry. Misunderstanding. I need to be able to globally disable all my links temporarily. Turn on and off the interaction. If I include an A link in my markup it will always display the hand cursor when I roll over and apply the format if I have one set even if there's no HREF. I have a HTML form element appearing over my Flash and I need to disable interaction across the entire textFlow object while this form is active.

Adobe Employee
April 12, 2010

How about going to the Sprite holding the TextLines and setting mouseEnabled and/or mouseChildren temporarily to false?

Hope that helps,

Richard