Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

TextEvent.LINK of Actionscript 3.0

This is a discussion on TextEvent.LINK of Actionscript 3.0 within the Tutorials forums, part of the Flash English category; A little while ago, we saw how to use the property htmlText of the TextField class to add a link ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 23-09-07, 12:39
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
TextEvent.LINK of Actionscript 3.0

A little while ago, we saw how to use the property htmlText of the TextField class to add a link to a text field with Actionscript 3.0.
That time, we did not use any event to tell Flash to redirect the user to a specific page.* The event was included in the HTML tag <a> using the attribute 'href'.
*
So, I ask myself, if I have a server script which returns the html text with the tag <a> but instead of using it to redirect the user to a web page,* I would like to reuse it in my script for other means, how would I proceed'

In this tutorial, we will see how to use an HTML string with a tag <a> assigned at the property 'htmlText' of a text field but without, once clicked, the redirection to another web page.

Using, the event LINK of the TextEvent class, we can tell the function called by this event to start a given code still retrieving the url from the HTML tag <a>.

Let us see how to do it' I create a FLA and save it as 'main.fla'.
I create a Document Class, an AS file saved as 'Main.as', implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.events.TextEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	public class Main extends MovieClip
	{
		private var field:TextField;
		
		public function Main()
		{
			createField();
		}
		
		private function createField():void
		{
			field=new TextField();
			addChild(field);
			
			field.selectable=false;
			field.wordWrap=true;
			field.textColor=0xFFFFFF;
			
			field.x=50;
			field.y=50;
			field.width=150;
			
			
			field.htmlText="Clicca quì per vedere il mio sito web";
			field.addEventListener(TextEvent.LINK,clickin);
		}
		
		private function clickin(evt:TextEvent):void
		{
			trace(evt.text);
		}
	}
}
Let us analyse the code

Properties

An instance if the TextField class
private var field:TextField;

Methods
createField();
I create a text field with the needed properties of the moment
field=new TextField();
addChild(field);
field.selectable=false;
field.wordWrap=true;
field.textColor=0xFFFFFF;
field.x=50;
field.y=50;
field.width=150;
Here is the principal point of the tutorial. The tag <a> is preceded of 'event'. This allows to tell Flash not to call directly the browser once the text clicked.
I add a listener to the event LINK of the TextEvent class which will call the method 'clickin'
field.htmlText="Clicca quì per vedere il mio sito web";
field.addEventListener(TextEvent.LINK,clickin);

clickin();
I now retrieve the url from the HTML string and we can now reuse it as wanted.
trace(evt.text);
The trace output will be as followed:

Stay tuned !
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !

Last edited by Flep; 28-08-08 at 07:08..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
link dispettoso annalisa Actionscript 3.0 base 1 11-06-08 19:47
Come controllare se ci troviamo in un link Donovant Actionscript 3.0 base 2 12-05-08 14:51
CS3 Datagrid (html link) rburns Actionscript 3.0 newbies 6 01-05-08 20:35
link xml...!!! lab81 Flash Italiano 10 02-11-07 18:21
TextEvent.LINK di Actionscript 3.0 Flep Articoli e tutorials 0 21-09-07 10:21


All times are GMT. The time now is 19:09.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap