Furniture links: Difference between revisions

From Whirled Club Wiki
Jump to navigation Jump to search
(Created page with "To create '''furniture with links''', you need to listen for the TextEvent generated by the TextField, and call navigateToURL. More details can be found in the [http://fir...")
 
m (Text replacement - """ to """)
Line 15: Line 15:
import com.whirled.FurniControl;
import com.whirled.FurniControl;


[SWF(width="50", height="50")]
[SWF(width="50", height="50")]
public class Link extends Sprite
public class Link extends Sprite
{
{
Line 34: Line 34:
     {
     {
         var tf :TextField = new TextField();
         var tf :TextField = new TextField();
         tf.htmlText = "Hello there, it's a <a href=\"event:http://google.com/\">link</a>.";
         tf.htmlText = "Hello there, it's a <a href=\"event:http://google.com/\">link</a>.";
         tf.width = 500;
         tf.width = 500;
         tf.height = 20;
         tf.height = 20;
         tf.addEventListener(TextEvent.LINK, handleLink);
         tf.addEventListener(TextEvent.LINK, handleLink);


         _ctrl.showPopup("It's a popup", tf, 500, 20);
         _ctrl.showPopup("It's a popup", tf, 500, 20);
     }
     }



Revision as of 18:43, 4 September 2018

To create furniture with links, you need to listen for the TextEvent generated by the TextField, and call navigateToURL. More details can be found in the Flash API documentation, but here's a simple example:

<actionscript> package {

import flash.display.Sprite;

import flash.events.MouseEvent; import flash.events.TextEvent;

import flash.net.URLRequest;

import flash.text.TextField;

import com.whirled.FurniControl;

[SWF(width="50", height="50")] public class Link extends Sprite {

   public function Link ()
   {
       _ctrl = new FurniControl(this);
       // something to click on
       var s :Sprite = new Sprite();
       s.graphics.beginFill(0xFF0000);
       s.graphics.drawCircle(25, 25, 25);
       s.graphics.endFill();
       addChild(s);
       s.addEventListener(MouseEvent.CLICK, handleClick);
   }
   protected function handleClick (event :MouseEvent) :void
   {
       var tf :TextField = new TextField();
       tf.htmlText = "Hello there, it's a <a href=\"event:http://google.com/\">link</a>.";
       tf.width = 500;
       tf.height = 20;
       tf.addEventListener(TextEvent.LINK, handleLink);
       _ctrl.showPopup("It's a popup", tf, 500, 20);
   }
   protected function handleLink (event :TextEvent) :void
   {
       flash.net.navigateToURL(new URLRequest(event.text));
   }
   protected var _ctrl :FurniControl;

} } </actionscript>