Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 1 of 1

Thread: TextEvent.LINK of Actionscript 3.0

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    TextEvent.LINK of Actionscript 3.0

    flash templates
    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 !

+ Reply to Thread

LinkBacks (?)

  1. 03-04-08, 09:30

Similar Threads

  1. How can I link .fla to .as
    By over_the_tos in forum Flash English
    Replies: 1
    Last Post: 29-10-09, 06:45
  2. creare un pulsante link flash cs4 actionscript 3.0
    By nozomi620 in forum Actionscript 3.0 avanzato
    Replies: 3
    Last Post: 17-10-09, 15:39
  3. Link con xml
    By thinkyogurt in forum Flash CS3 Design
    Replies: 11
    Last Post: 14-01-09, 12:02
  4. link xml...!!!
    By lab81 in forum Flash Italiano
    Replies: 10
    Last Post: 02-11-07, 17:21
  5. TextEvent.LINK di Actionscript 3.0
    By Flep in forum Articoli e tutorials
    Replies: 0
    Last Post: 21-09-07, 09:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts