2 Replies Latest reply on Aug 19, 2009 10:59 PM by Sreelash

    link each xml childnode in actionscript

    sktmind

      hello everyone,

      well, i've a problem here. since few days i'm trying to figure that out but i'm jut unable to resolve that.

      actually i've horizental images scroller added on my website using xml and actionscript 2.0. All images loaded perfectly and the scrolling function works great too but the main problem is that in actionscript all the links are in external flash however i want to use all links in internal flash using actionscript on all those images so that i can get the flash popup window from there on.I'm not able to find a method to link those images in actionscript to use flash functions. Below is my actionscript code and xml code.

       

       

      //ACTIONSCRIPT 2.0 CODE

       

       

      function initialise()
      {
          function movecontent()
          {
              targetX = -scroller.scroll_btn._x * ((content.myWidth - mask._width) / maxMove);
              oldX = content._x;
              content._x = content._x + Math.round(targetX - content._x);
              if (blurOn == "true")
              {
                  movement = oldX - content._x;
                  blur = new flash.filters.BlurFilter(15, 0, 1);
                  blur.blurX = Math.floor(Math.abs(movement * blurAmount / 3));
                  for (i = 0; i < item.length; i++)
                  {
                      content["clip" + i].filters = [blur];
                  } // end of for
              } // end if
          } // End of the function
          function scrollandpause()
          {
              if (itemNum < item.length)
              {
                  itemNum = 1 - Math.floor(content._x / itemWidth);
              }
              else
              {
                  itemNum = 0;
              } // end else if
              pos1 = scroller.scroll_btn._x;
              endPos = scroller.scroll_area._width / item.length * itemNum;
              if (endPos > maxScroll)
              {
                  itemNum = 0;
                  endPos = scroller.scroll_area._width / item.length * itemNum;
              } // end if
              myTween = new mx.transitions.Tween(scroller.scroll_btn, "_x", easingType, pos1, endPos, speed, true);
          } // End of the function
          function myInterval()
          {
              if (autoScroll == "true")
              {
                  intervalID = setInterval(this, "scrollandpause", pauseAmount);
              } // end if
          } // End of the function
          function scrollToClip()
          {
              if (snapOn == "true")
              {
                  itemNum = -Math.round(content._x / itemWidth);
                  pos1 = scroller.scroll_btn._x;
                  endPos = scroller.scroll_area._width / item.length * itemNum;
                  if (itemNum < item.length)
                  {
                      myTween = new mx.transitions.Tween(scroller.scroll_btn, "_x", easingType, pos1, endPos, snapSpeed, true);
                  } // end if
              } // end if
          } // End of the function
          if (scrollerOn == "false")
          {
              scroller._visible = false;
          } // end if
          this._visible = true;
          if (easingType == "Elastic")
          {
              easingType = mx.transitions.easing.Elastic.easeOut;
          }
          else if (easingType == "Strong")
          {
              easingType = mx.transitions.easing.Strong.easeOut;
          }
          else if (easingType == "Regular")
          {
              easingType = mx.transitions.easing.Regular.easeOut;
          }
          else if (easingType == "Bounce")
          {
              easingType = mx.transitions.easing.Bounce.easeOut;
          }
          else if (easingType == "Back")
          {
              easingType = mx.transitions.easing.Back.easeOut;
          }
          else if (easingType == "None")
          {
              easingType = mx.transitions.easing.None.easeOut;
          }
          else
          {
              easingType = mx.transitions.easing.Strong.easeOut;
          } // end else if
          itemNum = 0;
          scroller.scroll_btn._width = scroller.scroll_area._width / (content.myWidth / mask._width);
          maxMove = scroller.scroll_area._width - scroller.scroll_btn._width;
          maxScroll = Math.ceil(maxMove);
          this.onEnterFrame = function ()
          {
              movecontent();
          };
          myInterval();
          scroller.scroll_btn.onPress = function ()
          {
              this.gotoAndStop(2);
              myTween.stop();
              clearInterval(intervalID);
              scroller.scroll_btn.startDrag(0, maxMove, 0, 0);
          };
          scroller.scroll_btn.onRelease = scroller.scroll_btn.onReleaseOutside = function ()
          {
              this.gotoAndStop(1);
              stopDrag ();
              scrollToClip();
              myInterval();
          };
          scroller.prev.onPress = function ()
          {
              clearInterval(intervalID);
              if (itemNum > 0)
              {
                  --itemNum;
              } // end if
              pos1 = scroller.scroll_btn._x;
              endPos = scroller.scroll_area._width / item.length * itemNum;
              myTween.stop();
              myTween = new mx.transitions.Tween(scroller.scroll_btn, "_x", easingType, pos1, endPos, speed, true);
              myInterval();
          };
          scroller.next.onPress = function ()
          {
              clearInterval(intervalID);
              if (itemNum < item.length - 1)
              {
                  ++itemNum;
              } // end if
              pos1 = scroller.scroll_btn._x;
              endPos = scroller.scroll_area._width / item.length * itemNum;
              if (endPos > maxScroll)
              {
                  --itemNum;
              }
              else
              {
                  myTween.stop();
                  myTween = new mx.transitions.Tween(scroller.scroll_btn, "_x", easingType, pos1, endPos, speed, true);
              } // end else if
              myInterval();
          };
      } // End of the function
      function loadXML(loaded)
      {
          if (loaded)
          {
              item = this.firstChild.childNodes;
              autoScroll = this.firstChild.attributes.autoScroll;
              pauseAmount = this.firstChild.attributes.pauseAmount;
              snapOn = this.firstChild.attributes.snapOn;
              snapSpeed = this.firstChild.attributes.snapSpeed;
              speed = this.firstChild.attributes.speed;
              blurOn = this.firstChild.attributes.blurOn;
              blurAmount = this.firstChild.attributes.blurAmount;
              scrollerOn = this.firstChild.attributes.scrollerOn;
              easingType = this.firstChild.attributes.easingType;
              urlTarget = this.firstChild.attributes.urlTarget;
              itemsPerScreen = this.firstChild.attributes.itemsPerScreen;
              if (scrollerOn == "true")
              {
                  mask._height = movieClipHeight - 20;
              }
              else
              {
                  mask._height = movieClipHeight;
              } // end else if
              mask._width = movieClipWidth;
              itemWidth = mask._width / itemsPerScreen;
              itemHeight = mask._height;
              content.myWidth = itemWidth * item.length;
              if (content.myWidth < mask._width)
              {
                  scroller._visible = false;
                  scrollerOn = "false";
                  mask._height = movieClipHeight;
                  itemHeight = mask._height;
              } // end if
              scroller.scroll_area._width = mask._width - 40;
              scroller.next._x = mask._width - 22;
              scroller._y = mask._height + 2;
              scroller._x = 20;
              for (var _loc3 = 0; _loc3 < item.length; ++_loc3)
              {
                  var _loc2 = content.attachMovie("clip", "clip" + _loc3, _loc3);
                  _loc2.mask._width = itemWidth;
                  _loc2.mask._height = itemHeight;
                  _loc2._x = itemWidth * _loc3;
                  _loc2.preloader._y = _loc2.mask._height / 2;
                  _loc2.preloader._x = _loc2.mask._width / 2;
                  _loc2.preloader.inner.colour.cacheAsBitmap = true;
                  _loc2.preloader.inner.mask.cacheAsBitmap = true;
                  _loc2.preloader.inner.colour.setMask(_loc2.preloader.inner.mask);
                  _loc2.link = item[_loc3].attributes.link;
                  _loc2.image = item[_loc3].attributes.image;
                  _loc2.image_mc._lockroot = true;
                  myClip.loadClip(_loc2.image, _loc2.image_mc);
                  _loc2.onRelease = function ()
                  {
                      getURL(this.link, urlTarget);
                  };
              } // end of for
              initialise();
          } // end if
      } // End of the function
      Stage.scaleMode = "noScale";
      Stage.align = "TL";
      movieClipWidth = Stage.width;
      movieClipHeight = Stage.height;
      this._visible = false;
      myClip = new MovieClipLoader();
      preload = new Object();
      myClip.addListener(preload);
      preload.onLoadStart = function (targetMC)
      {
          targetMC._parent.preloader._visible = true;
      };
      preload.onLoadProgress = function (targetMC, lBytes, tBytes)
      {
      };
      preload.onLoadComplete = function (targetMC)
      {
          targetMC._parent.preloader._visible = false;
      };
      preload.onLoadInit = function (targetMC)
      {
          targetMC._x = itemWidth / 2 - targetMC._width / 2;
          targetMC._y = itemHeight / 2 - targetMC._height / 2;
      };
      if (_root.xmlURL == undefined)
      {
          _root.xmlURL = "items.xml";
      } // end if
      myXml = new XML();
      myXml.ignoreWhite = true;
      myXml.onLoad = loadXML;
      myXml.load("config/dressing.xml");

       

       

       

       

       

       

       

       

       

      //AND HERE IS THE XML FILE

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <xml
      autoScroll="true"
      pauseAmount="8000"
      snapOn="true"
      snapSpeed="10"
      speed="2"
      blurOn="false"
      blurAmount="1"
      scrollerOn="true"
      easingType="Strong"
      urlTarget="_blank"
      itemsPerScreen = "3"
      >
          <item link="http://www.link.com" image="images/dressing/dressing1.jpg"/>
          <item link="http://www.link.com" image="images/dressing/dressing2.jpg"/>
          <item link="http://www.link.com" image="images/dressing/dressing3.jpg"/>
          <item link="http://www.link.com" image="images/products/dressing/dressing4.jpg"/>
          <item link="http://www.link.com" image="images/products/dressing/dressing5.jpg"/>
          <item link="http://www.link.com" image="images/products/dressing/dressing6.jpg"/>
         
      </xml>