Posted By

blainejoubert on 01/08/09


Tagged

arguments passing navigateToURL CustomObject


Versions (?)

Loading an image from the library and assigning it a url


 / Published in: ActionScript 3
 

This is based on the example from http://blog.onebyonedesign.com/?p=60.

You need to create a thumbnail in the library with Box as the linkage ID

  1. //Custom Class file code
  2.  
  3. package {
  4.  
  5. import flash.display.Sprite;
  6.  
  7. public class CustomObject extends Sprite {
  8.  
  9.  
  10. private var _link:String;
  11.  
  12. public function CustomObject(link:String):void {
  13.  
  14. _link = link;
  15.  
  16. var box:Box = new Box() // Box is the linkage id name from the box movieclip in the library
  17. addChild(box)
  18. }
  19.  
  20. public function get link():String { return _link; }
  21.  
  22. public function set link(value:String):void {
  23. _link = value;
  24. }
  25. }
  26. }
  27.  
  28. //-------------------------------------------------------------------------------------------------
  29.  
  30. //Document Class file
  31.  
  32. package {
  33.  
  34. import flash.display.*;
  35. import flash.events.*;
  36. import flash.net.*;
  37.  
  38. public class CustomObjectTest extends Sprite {
  39.  
  40. public function CustomObjectTest():void {
  41. var links:Array = new Array("link1.html","link2.html","link3.html","link4.html")
  42. for (var n:Number=0; n<4; n++){
  43. var co:CustomObject = new CustomObject(links[n]);
  44. co.addEventListener(MouseEvent.CLICK, onClick);
  45. addChild(co);
  46. co.y = 100*n;
  47. }
  48. }
  49.  
  50. private function onClick(me:MouseEvent):void {
  51.  
  52. var siteLink:URLRequest = new URLRequest( me.currentTarget.link );
  53. navigateToURL( siteLink );
  54. }
  55. }
  56. }

Report this snippet  

You need to login to post a comment.