Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to make hyperlinks clickable?

Participant ,
Aug 23, 2011 Aug 23, 2011

Im have data retrieved from a API, there are hyperlinks within this data, so i want the hyperlinks to be 'clickable' I read up many ways of making a textfield clickable links but they all made you type in he specific link you want. I need it to be clickable if there is a link recieved from the data..

TOPICS
ActionScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 23, 2011 Aug 23, 2011

Assign the text to the htmlText property of the textfield and write the links as html links.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 23, 2011 Aug 23, 2011

by this are you meaning the div icons on the text field properties panel. Or actually assign it from within the actionscript?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 23, 2011 Aug 23, 2011

Actionscript.  Look up the htmlText property of the TextField class in the help documentation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 23, 2011 Aug 23, 2011

Ok, i looked it up. But I have no Idea how to implement it into my code.

My code:

var tf2:TextField=new TextField();

feed1.text = facebookFeed.message;

feed2.text = facebookFeed[2].message;

feed3.text = facebookFeed[3].message;

feed4.text = facebookFeed[4].message;

feed5.text = facebookFeed[5].message;

feed6.text = facebookFeed[6].message;

feed7.text = facebookFeed[7].message;

feed8.text = facebookFeed[8].message;

the ducumentation:

package {
    import flash.display.Sprite;
    import flash.text.StyleSheet;
    import flash.text.TextField;

    public class TextField_text extends Sprite {
        public function TextField_text() {
            var tf1:TextField = createCustomTextField(10, 10, 400, 22);
            tf1.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";

            // htmlText: <P ALIGN="LEFT"><FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0"><b>Lorem ipsum dolor sit amet.</b></FONT></P>
            trace("htmlText: " + tf1.htmlText);
            // text: Lorem ipsum dolor sit amet.
            trace("text: " + tf1.text);
            
            var tf2:TextField = createCustomTextField(10, 50, 400, 22);
            tf2.styleSheet = new StyleSheet();
            tf2.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";
            // htmlText: <b>Lorem ipsum dolor sit amet.</b>
            trace("htmlText: " + tf2.htmlText);
            // text: Lorem ipsum dolor sit amet.
            trace("text: " + tf2.text);
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            addChild(result);
            return result;
        }
    }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 23, 2011 Aug 23, 2011

You are assigning to the "text" property in your code, which is not what I said you should do.  You should assign the the "htmlText" property, and you data needs to have html links defined in it.

As far as what you show for that section of the help documentation, you should read the whole section to gain an understanding and not just jump to the example at the end to try to glom a solution from it.  Learning involves more work than someone handing you a piece of code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 24, 2011 Aug 24, 2011

As Ned suggested - you need to write html anchor tag. For example:

myTextField.htmlText = "<p>this is the link <a href='http://www.google.com/'>that can be clicked</a></p>";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 24, 2011 Aug 24, 2011

But the problem is. I dont know if there is allways going to be a hyperlink to click.

The data is recieved from a twitter tweet. So sometimes there will be a url within the tweet, othertimes not.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 24, 2011 Aug 24, 2011

So, based on twitter data you need to figure out when you get link. basically, it is not AS3 question but something related to conventions twitter uses to compose data. Give an example of data received from twitter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 24, 2011 Aug 24, 2011

Well i call the twiiter feed, its decoded as JSON, then displayed through actionscript.

Here's the code:

import flash.events.MouseEvent;

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.events.Event;

import com.adobe.serialization.json.JSON;

import flash.text.TextFieldAutoSize;

import flash.text.TextField;

//twitter api //twitter api //twitter api //twitter api //twitter api //twitter api

var loader:URLLoader = new URLLoader(new URLRequest("https://api.twitter.com/1/statuses/user_timeline.json?screen_name=XXXX"));

loader.addEventListener(Event.COMPLETE, loadComplete);

function loadComplete(e:Event):void

{

processData(e.target.data);

}

function processData(data:String):void

{

var tweets:Array = JSON.decode(data) as Array;

for (var i:int=0; i<8; i++)

{

var tf:TextField=new TextField();

tweet1.text = tweets[1].text;

tweet2.text = tweets[2].text;

tweet3.text = tweets[3].text;

tweet4.text = tweets[4].text;

tweet5.text = tweets[5].text;

tweet6.text = tweets[6].text;

tweet7.text = tweets[7].text;

tweet8.text = tweets[8].text;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2011 Aug 24, 2011

Hyperlinks in tweets obtained via API all begin with http:// or https://, or all begin with http://t.co (at least for URLs with 19 characters or more) - either way you can use RegExp to create <a> tag around it in AS. Also do not forget @ (Twitter name) and # (Hashtag) - they should be hyperlinks too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 24, 2011 Aug 24, 2011

OOOOH so i think i understand slightly more now. I need to tell the compiler to look out for http://? or @USER?

How do you do this though?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2011 Aug 24, 2011
LATEST

RegExp

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/RegExp.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines