2 Replies Latest reply on Oct 9, 2008 1:35 AM by san00001

    problem in creating dynamic links

    san00001 Level 1
      Hi,

      I am trying to create dynamic links by creating labels dynamically.the datas are comming from two arrays.one array contains the text to the labels and another contains links to the labels.While clicking a particular link it should open the particular link.

      my code is

      var myArray:Array=["contactus.jsp","feedback.jsp","faq.jsp","he.jsp"];
      var myArray1:Array=["contactus","feedback","faq","he"];
      public function create():void
      {
      var i:int = 0;
      for (i = 0; i < myArray1.length; i++)
      {
      var lbl:Label=new Label();
      lbl.htmlText=<a href='event:{myArray }'>{myArray1}</a>
      lbl.addEventListener(MouseEvent.CLICK, linkHandler);
      hh.addChild(lbl);
      }
      }

      public function linkHandler(event:Event):void {
      // myTA.text="link occured.";
      // Open the link in a new window.
      navigateToURL(new URLRequest(event.currentTarget), '_blank')
      }

      This code is not working.someone pls help me to achive this
        • 1. problem in creating dynamic links
          fspjotr
          Hi,

          First of all, working with a repeater and a dataprovider woudl work much cleaner and faster.

          This aside, reason code is not working is this:

          when accessing an element in an array, use square brackets
          also, there is no variable substitution in actionscript
          thus:
          • 2. Re: problem in creating dynamic links
            san00001 Level 1
            Hi,

            Thanx for ur reply.If i use repeater i can create repeated label and i can assign text to the labels from an array by providing the array as dataprovider to repeater.But hw can i assign links to that labels.I think the following code has some problem.pls help me

            public function linkHandler(event:Event):void {

            // Open the link in a new window.
            navigateToURL(new URLRequest(event.currentTarget), '_blank')
            }