Furniture links: Difference between revisions

From Whirled Club Wiki
Jump to navigation Jump to search
m (Text replacement - """ to """)
m (Text replacement - ">" to ">")
Line 1: Line 1:
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://first.whirled.com/code/asdocs/ Flash API documentation], but here's a simple example:
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://first.whirled.com/code/asdocs/ Flash API documentation], but here's a simple example:


<actionscript>
<actionscript>
package {
package {


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;
Line 50: Line 50:
}
}
}
}
</actionscript>
</actionscript>
[[Category:Furniture tutorials]]
[[Category:Furniture tutorials]]

Revision as of 19:48, 5 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>