4 Replies Latest reply on Jun 2, 2009 6:45 AM by kglad

    ActionScript 3 - XML - NavigateToURL

    CyberSam

      Ok there are many tutorials out there on how to use this function, what I am trying to do and can't seem to find a tutorial on is using navigateToURL with the "mailto" email address being populated from an XML list.

       

      For example you have a list of offices and each office has a lead. I want to populate a List component with the office name, and when clicked I want it to open the email client and populate the To: and Subject line from the xml file.

       

      What I have so far populates the Office name into the list and when clicked  the mail client will open but doesnt populate the To because I can't figure it out.

       

      I believe I need to specify a var to pull the email address from the xml list, I just cant seem to get it right.

       

       

      here is a snippet example of my xml code

      ************************************

      <officeleads>
        <office>
         <officenm>PDX</officenm>
         <emllink>myemail@domian.com</emllink>   <-------- I want this to populate the "To:" in an email
        </office>
      </officeleads>

      *************************************

       

      and here is my ActionScript

       

      *************************************

      var leadloader:URLLoader = new URLLoader();
      leadloader.addEventListener(Event.COMPLETE, onLoaded);

      leadlist.addEventListener(Event.CHANGE, openMailClient);

      function openMailClient(l:Event):void
      {
      var request:URLRequest = new URLRequest();
      request.url="mailto:"                 <----------  this is where I know I need to somehow specify the emllink in the xml file to be filled into the "To:"
      navigateToURL(request,"Self");
      }
      var xml:XML;
      function onLoaded (l:Event):void
      {
        xml = new XML(l.target.data);
        var offlst:XMLList = xml.office;
        for (var i:uint=0; i<offlst.length();i++)
        {
         leadlist.addItem({data:offlst.officenm.text()[i],
             label:offlst.officenm.text()[i]});
        } 
      }

      leadloader.load(new URLRequest("officeleads.xml"));

       

       

      Any help will be greatly appreciated.

       

      Thanks

       

      Sam

      AS3 Noob

        • 1. Re: ActionScript 3 - XML - NavigateToURL
          kglad Adobe Community Professional & MVP

          try:

           

          import fl.events.ListEvent;

           

          var leadloader:URLLoader = new URLLoader();
          leadloader.addEventListener(Event.COMPLETE, onLoaded);

           

          leadlist.addEventListener(ListEvent.ITEM_CLICK, openMailClient);

           

          function openMailClient(e:ListEvent):void {
             var request:URLRequest=new URLRequest("mailto:"+leadlist.getItemAt(int(e.rowIndex)).data);
              navigateToURL(request,"_self");
          }
          var xml:XML;
          function onLoaded(l:Event):void {
              xml = new XML(l.target.data);
              var offlst:XMLList = xml.office;
              for (var i:uint=0; i<offlst.length(); i++) {
                 leadlist.addItem({data:offlst.emllink.text()[i],
                         label:offlst.officenm.text()[i]});

              }
          }

           

          leadloader.load(new URLRequest("officeleads.xml"));

          • 2. Re: ActionScript 3 - XML - NavigateToURL
            CyberSam Level 1

            I can kinda see where you are going, after entering your suggest code I get the following error.

             

            1120:Access of undefined property e.

             

            Source

             

            Var request:URLRequest= newURLRequest("mailto:"_leadlist.getItemAt(int(e.rowIndex)).data);

             

             

            thanks for your help.

             

            Sam

            AS3 Noob

            • 3. Re: ActionScript 3 - XML - NavigateToURL
              CyberSam Level 1

              Hey -

               

              After I re-read your code suggestion I realised you had made more changes to what I had posted other than the text in red. I rebuilt it and works  perfectly.

               

              Thanks tons.

               

              Sam

               

              AS3 Noob

              • 4. Re: ActionScript 3 - XML - NavigateToURL
                kglad Adobe Community Professional & MVP

                you're welcome.

                 

                (and sorry about failing to highlight that event-change.  i went back and corrected it in case someone else checks this thread.)

                1 person found this helpful