3868 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
flashjunkie says

Hi guys,

Starting to tear my hair out here, im trying to add text to a RichText component using AS3 , some of the text is just plain text but some will require a click event to fire an AS function.

Does anyone have any ideas how I can accomplish this in AS3 ?

public function buildPathComponent():void {

    for(var i:Number = 0; i<ParentStructure.length; i++) {

        AddLabel(ParentStructure[i].Name, true, ParentStructure[i].CatUrl);

        if(i+1 != ParentStructure.length) {

            AddLabel(" >> ", false, "");

        }

    }

}

public function AddLabel(str:String, isCat:Boolean, ClickUrl:String):void {

    if(isCat) {
        //Add clickable text to textflow
    } else {
        //add plain text to textflow
    }

}

my end result should look like this…

Category Link >> Category Link >> Category Link

the ’>>’ parts will be a different color and not clickable!

Thanks guys!

374 posts
  • Has referred 50+ members
  • Has sold $10,000+ on Envato Market
  • Had an item featured in an Envato Bundle
  • Has collected 10+ items on Envato Market
+10 more
MarcoSecchi Envato team says

Hey Jay, you can use ‘event:’ on a piece of text and then listen to the TextEvent.LINK event:

public function test2()
{
    var t:TextField = new TextField();
    t.htmlText = "Hello <a href="event:customEventValue">World</a>!";
    t.addEventListener(TextEvent.LINK, onLink);

    addChild(t);
}

protected function onLink(event:TextEvent):void
{
    trace(event.text); // this will trace 'customEventValue'
    // code logic
}

hope this helps :)

marco

3868 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
flashjunkie says

Hey marco,

thanks for the reply, I’ve fixed the problems i was having but have added your code to my snippets as I am sure that will be very useful in the future!

Jay

by
by
by
by
by
by