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 "<")
 
(2 intermediate revisions by the same user not shown)
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:


&lt;actionscript&gt;
<actionscript>
package {
package {


Line 15: Line 15:
import com.whirled.FurniControl;
import com.whirled.FurniControl;


[SWF(width=&quot;50&quot;, height=&quot;50&quot;)]
[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 = &quot;Hello there, it's a &lt;a href=\&quot;event:http://google.com/\&quot;&gt;link&lt;/a&gt;.&quot;;
         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(&quot;It's a popup&quot;, tf, 500, 20);
         _ctrl.showPopup("It's a popup", tf, 500, 20);
     }
     }


Line 50: Line 50:
}
}
}
}
&lt;/actionscript&gt;
</actionscript>
[[Category:Furniture tutorials]]
[[Category:Furniture tutorials]]

Latest revision as of 20:43, 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>