3868 posts
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 100 and 499 items
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 6-7 years
+4 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!

372 posts
  • Author had a File in an Envato Bundle
  • Senior Reviewer
  • Won a Competition
  • Author had a Free File of the Month
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Envato Staff
  • Has been a member for 7-8 years
+6 more
MarcoSecchi Reviewer 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
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 100 and 499 items
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 6-7 years
+4 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