7 Replies Latest reply on Dec 17, 2009 1:00 PM by Ned Murphy

    AS 2 Conundrum

    leatherjeep Level 1

      Happy Holidays everyone,

       

      I've looked at this problem a hundred times but cannot seem to see what's causing my problem.  I am looking at this ActionScript in my Flash file:

       

       

      import mx.transitions.Tween;

      import mx.transitions.easing.*;

      var tween_type = Strong.easeInOut;

      var arr1:Array = new Array();//the array that will hold the data of each

      var space_x:Number = 10;//the x space between news

      var space_y:Number = 10;//the y space between news

      var original_x:Number = c_holder.c_mc._x;

      var original_y:Number = c_holder.c_mc._y;

      var distance_x:Number;//the x distantce between items

      var distance_y:Number;//the y distantce between items

      var num:Number = 0;//ckeck number for auto play take 0=off 1=on;

      var i:Number = 0;

      var j:Number = 0;

      var k:Number = -1;

      var a_no:Number = 0;

      var duration:Number = 6000;//time to transfere between items

       

      var xl:XML = new XML();

      xl.ignoreWhite = true;

      xl.onLoad = function(ok) {

      if (ok) {

      var xdata:XMLNode = this.firstChild;

      for (i=0; i<xdata.childNodes.length; i++) {

      arr1.push({path:xdata.childNodes[i].childNodes[0].firstChild, title:xdata.childNodes[i].childNodes[1].firstChild, desc:xdata.childNodes[i].childNodes[2].firstChild, booger:xdata.childNodes[i].childNodes[3].firstChild, date:xdata.childNodes[i].childNodes[4].firstChild});

      }

      }

      //distribute items in its position

      DisplayNews();

      };

      xl.load("newsXML.xml");

      function DisplayNews() {

      for (i = 0; i<arr1.length; i++) {

      mc = _root.c_holder.c_mc.attachMovie("itms","itm"+i,i);

      mc.img_holder.img_mc.loadMovie(arr1[i].path);

      mc.header = arr1[i].title;

      mc.details = arr1[i].desc;

      mc.dates = arr1[i].date;

      mc.onRelease = function(){

      getURL(arr1[i].booger, "_blank");

      }

      distance_x = mc._width + space_x ;

      distance_y = mc._height + space_y ;

      if (i%3 == 0) {

      j = 0;

      k++;

      }

      mc._x = j * distance_x;

      mc._y = k * distance_y;

      j++;

      }

      slideAnim(0);

       

      }

      //next button

      tools.next_btn.onRelease = function(){

      slideAnim(next_no);

      }

      //previous button

      tools.prev_btn.onRelease = function(){

      slideAnim(previous_no);

      }

      //first button

      tools.first_btn.onRelease = function(){

      slideAnim(0);

      }

      //lask button

      tools.last_btn.onRelease = function(){

      slideAnim(arr1.length-1);

      }

      //animation start

      function slideAnim(no)

      {

      if( !no && no != 0 && a_no == arr1.length )

      {

      no = a_no = 0;

      }

      else if( !no && no != 0 )

      {

      no = a_no;

      }

      else

      {

      a_no = no;

      }

      a_no++;

      tools.record = no+1  + " / " + (arr1.length);

      next_no = no + 1;

      previous_no = no - 1;

       

      tools.next_btn._visible = true;

      tools.prev_btn._visible = true;

       

      if( no == arr1.length - 1 ){

      tools.next_btn._visible = false;

      }else if( no == 0 ){

      tools.prev_btn._visible = false;

      }

      j = Math.round(no % 3);

      k = Math.floor(no / 3);

      old_x = c_holder.c_mc._x;

      old_y = c_holder.c_mc._y;

      new_x = original_x - j * distance_x;

      new_y = original_y - k * distance_y;

      var tw1:Tween =new Tween(c_holder.c_mc, "_x", tween_type, old_x, new_x, 1.2, true);

      var tw2:Tween =new Tween(c_holder.c_mc, "_y", tween_type, old_y, new_y, 1.2, true);

      }

      auto_btn.gotoAndStop(2);

      auto_play = setInterval(slideAnim, duration);

      auto_btn.onRelease = function()

      {

      if( num ==0 ){

      this.gotoAndStop(1);

      clearInterval(auto_play);

      num = 1;

      }else if(num ==1){

      this.gotoAndStop(2);

      auto_play = setInterval(slideAnim, duration);

      num = 0

      }

      }

       

       

       

       

      My particular problem is with this section:

       

      mc.onRelease = function(){

      getURL(arr1[i].booger, "_blank");

      }

       

       

       

       

      The function itself works, when the SWF is clicked, a new window opens like it should, but the URL comes up as Undefined.  I know that the XML for the URL is loading into the SWF, because if I swap its location in the XML Nodes, it will show up correctly in one of the other fields inside the SWF when it plays.

       

       

      So I'm throwing this out here for hopefully a fresh set of eyes to look at and point me in the right direction.

       

       

      Many thanks,

       

       

      Gary

        • 1. Re: AS 2 Conundrum
          Ned Murphy Adobe Community Professional & MVP

          Have you traced thru the arr1 data to confirm that you have what you think you do in the objects' data?

          • 2. Re: AS 2 Conundrum
            leatherjeep Level 1

            Ned,

             

            Happy Holidays and thanks for responding.

             

            I run the trace, but if I put the trace command within the mc.onrelease function it comes up Undefined for that parameter.  If I set up

             

            mc.booger = arr1[i].booger;

             

            prior to the mc.onrelease function, and run the trace against that, then the correct data shows up in the trace.  So it appears it's something particular with the mc.onRelease function.

             

             

             

            Gary

            • 3. Re: AS 2 Conundrum
              Ned Murphy Adobe Community Professional & MVP

              Try tracing the value of i in that onRelease function along with arr1.length.  If they are equal, the problem lies therein.

              • 4. Re: AS 2 Conundrum
                leatherjeep Level 1

                Ned,

                 

                They are not the same:

                 

                [i] = 1

                arr1.lenght = 40

                 

                 

                 

                Gary

                • 5. Re: AS 2 Conundrum
                  kglad Adobe Community Professional & MVP

                  he meant, use trace(i).  that will be the last value of i in your for-loop, not the value of i when your button

                  handler was created.

                   

                  use:

                   


                   

                   

                   

                  import mx.transitions.Tween;

                  import mx.transitions.easing.*;

                  var tween_type = Strong.easeInOut;

                  var arr1:Array = new Array();//the array that will hold the data of each

                  var space_x:Number = 10;//the x space between news

                  var space_y:Number = 10;//the y space between news

                  var original_x:Number = c_holder.c_mc._x;

                  var original_y:Number = c_holder.c_mc._y;

                  var distance_x:Number;//the x distantce between items

                  var distance_y:Number;//the y distantce between items

                  var num:Number = 0;//ckeck number for auto play take 0=off 1=on;

                  var i:Number = 0;

                  var j:Number = 0;

                  var k:Number = -1;

                  var a_no:Number = 0;

                  var duration:Number = 6000;//time to transfere between items

                   

                  var xl:XML = new XML();

                  xl.ignoreWhite = true;

                  xl.onLoad = function(ok) {

                  if (ok) {

                  var xdata:XMLNode = this.firstChild;

                  for (i=0; i<xdata.childNodes.length; i++) {

                  arr1.push({path:xdata.childNodes[i].childNodes[0].firstChild, title:xdata.childNodes[i].childNodes[1].firstChild, desc:xdata.childNodes[i].childNodes[2].firstChild, booger:xdata.childNodes[i].childNodes[3].firstChild, date:xdata.childNodes[i].childNodes[4].firstChild});

                  }

                  }

                  //distribute items in its position

                  DisplayNews();

                  };

                  xl.load("newsXML.xml");

                  function DisplayNews() {

                  for (i = 0; i<arr1.length; i++) {

                  mc = _root.c_holder.c_mc.attachMovie("itms","itm"+i,i);

                  mc.img_holder.img_mc.loadMovie(arr1[i].path);

                  mc.header = arr1[i].title;

                  mc.details = arr1[i].desc;

                  mc.dates = arr1[i].date;

                  mc.ivar=i;

                  mc.onRelease = function(){

                  getURL(arr1[this.ivar].booger, "_blank");

                  }

                  /*

                  or:

                  mc.urlS = arr1[i].booger

                  mc.onRelease=function(){

                  getURL(this.urlS,"_blank");

                  }

                  */

                  distance_x = mc._width + space_x ;

                  distance_y = mc._height + space_y ;

                  if (i%3 == 0) {

                  j = 0;

                  k++;

                  }

                  mc._x = j * distance_x;

                  mc._y = k * distance_y;

                  j++;

                  }

                  slideAnim(0);

                   

                  }

                  //next button

                  tools.next_btn.onRelease = function(){

                  slideAnim(next_no);

                  }

                  //previous button

                  tools.prev_btn.onRelease = function(){

                  slideAnim(previous_no);

                  }

                  //first button

                  tools.first_btn.onRelease = function(){

                  slideAnim(0);

                  }

                  //lask button

                  tools.last_btn.onRelease = function(){

                  slideAnim(arr1.length-1);

                  }

                  //animation start

                  function slideAnim(no)

                  {

                  if( !no && no != 0 && a_no == arr1.length )

                  {

                  no = a_no = 0;

                  }

                  else if( !no && no != 0 )

                  {

                  no = a_no;

                  }

                  else

                  {

                  a_no = no;

                  }

                  a_no++;

                  tools.record = no+1  + " / " + (arr1.length);

                  next_no = no + 1;

                  previous_no = no - 1;

                   

                  tools.next_btn._visible = true;

                  tools.prev_btn._visible = true;

                   

                  if( no == arr1.length - 1 ){

                  tools.next_btn._visible = false;

                  }else if( no == 0 ){

                  tools.prev_btn._visible = false;

                  }

                  j = Math.round(no % 3);

                  k = Math.floor(no / 3);

                  old_x = c_holder.c_mc._x;

                  old_y = c_holder.c_mc._y;

                  new_x = original_x - j * distance_x;

                  new_y = original_y - k * distance_y;

                  var tw1:Tween =new Tween(c_holder.c_mc, "_x", tween_type, old_x, new_x, 1.2, true);

                  var tw2:Tween =new Tween(c_holder.c_mc, "_y", tween_type, old_y, new_y, 1.2, true);

                  }

                  auto_btn.gotoAndStop(2);

                  auto_play = setInterval(slideAnim, duration);

                  auto_btn.onRelease = function()

                  {

                  if( num ==0 ){

                  this.gotoAndStop(1);

                  clearInterval(auto_play);

                  num = 1;

                  }else if(num ==1){

                  this.gotoAndStop(2);

                  auto_play = setInterval(slideAnim, duration);

                  num = 0

                  }

                  }

                   

                   

                   

                   

                  My particular problem is with this section:

                   

                   

                  mc.onRelease = function(){

                  getURL(arr1[i].booger, "_blank");

                  }

                   

                   

                   

                   

                  The function itself works, when the SWF is clicked, a new window opens like it should, but the URL comes up as Undefined.  I know that the XML for the URL is loading into the SWF, because if I swap its location in the XML Nodes, it will show up correctly in one of the other fields inside the SWF when it plays.

                   

                   

                  So I'm throwing this out here for hopefully a fresh set of eyes to look at and point me in the right direction.

                   

                   

                  Many thanks,

                   

                   

                  Gary

                  • 6. Re: AS 2 Conundrum
                    leatherjeep Level 1

                    Either way, it's not helpful.  If I define something like mc.myurl = arr1[i].booger; and then display that via trace or even on the screen during the SWF testing, it appears as it should.  Drop it into this archaic Actionscript language using the syntax they demand, and it doesn't work. 

                     

                    And we're all wondering why Adobe's sales are plummeting along with their stock price.

                     

                     

                     

                     

                    Gary

                    • 7. Re: AS 2 Conundrum
                      Ned Murphy Adobe Community Professional & MVP

                      What I intended for you to do was...

                       

                      mc.onRelease = function(){

                      trace(i);

                      trace(arr1.length);

                      getURL(arr1[i].booger, "_blank");

                      }

                       

                      As for your choosing an older version of actionscript to work in, you made the choice, and when used properly it works quite well.

                      1 person found this helpful