0 Replies Latest reply on Mar 16, 2010 4:54 PM by mixmastermichael

    A few questions with XML and Flash

    mixmastermichael

      Hi there.

       

      I am currently trying to create a 3d carousel using AS2 and XML.  I've made a lot of progress, but there ar e few things I am still struggling with and was hopoing that someone here could please steer me in the right direction.

       

      Here is a URL where the Carousel can be found:

      http://iongeo.com/ru_innovation_test_dev/carousel_test.html

       

      Here are a few of the things I am wondering:

       

      1.  I would like to be ablle to add a back button movide clip, similar to how the tooltip movie clip is presented now; this movie clip would be able to allow users to go back home to the caousel.  I can't seem to get it to load correctly however, I would imagine that it would be set up similarly to how the tooltip icon is set up now, but to be able to have an alpha of 100 when the text is loaded in.

       

      2.  I was also wondering how I mihgt be able to add links to my .xml document to be able to call in URLs on the web.  I've tried several things using the CDATA approach, but can't seem to get it to work.

       

      I would greatly appreciate any assistance privded and am very greatful for any consideration thac ould be provided.  Please let me know if there is anything htat I should clarify on.

       

      Below is my code for AS2 and XML so that you might see how things are currently working.

       

      import mx.utils.Delegate;
      import mx.transitions.Tween;
      import mx.transitions.easing.*;

       

      var numOfItems:Number;
      var radiusX:Number = 200;
      var radiusY:Number = 75;
      var centerX:Number = 300;
      var centerY:Number = 150;
      var speed:Number = 0.00;
      var perspective:Number = 20;
      var home:MovieClip = this;
      theText._alpha = 0;
      theHeader._alpha = 0;

       

      var tooltip:MovieClip = this.attachMovie("tooltip","tooltip",8000);
      tooltip._alpha = 0;

       

      var xml:XML = new XML();
      xml.ignoreWhite = true;

       

      xml.onLoad = function()
      {
          var nodes = this.firstChild.childNodes;
          numOfItems = nodes.length;
          for(var i=0;i<numOfItems;i++)
          {
              var t = home.attachMovie("item","item"+i,i+1);
              t.angle = i * ((Math.PI*2)/numOfItems);
              t.onEnterFrame = mover;
              t.toolText = nodes[i].attributes.tooltip;
              t.content = nodes[i].attributes.content;
              t.header = nodes[i].attributes.header;
              t.icon.inner.loadMovie(nodes[i].attributes.image);
              t.r.inner.loadMovie(nodes[i].attributes.image);
              t.icon.onRollOver = over;
              t.icon.onRollOut = out;
              t.icon.onRelease = released;
          }
      }
      function over()
      {
          //BONUS Section
          home.tooltip.tipText.text = this._parent.toolText;
          home.tooltip._x = this._parent._x;
          home.tooltip._y = this._parent._y - this._parent._height/2;
          home.tooltip.onEnterFrame = Delegate.create(this,moveTip);
          home.tooltip._alpha = 100;
      }

       

      function out()
      {
          delete home.tooltip.onEnterFrame;
          home.tooltip._alpha = 0;
      }
      function released()
      {
          //BONUS Section
          home.tooltip._alpha = 100;
          for(var i=0;i<numOfItems;i++)
          {
              var t:MovieClip = home["item"+i];
              t.xPos = t._x;
              t.yPos = t._y;
              t.theScale = t._xscale;
              delete t.icon.onRollOver;
              delete t.icon.onRollOut;
              delete t.icon.onRelease;
              delete t.onEnterFrame;
              if(t != this._parent)
              {
                  var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,t._xscale,0,1,true);
                  var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,t._yscale,0,1,true);
                  var tw3:Tween = new Tween(t,"_alpha",Strong.easeOut,100,0,1,true);
              }
              else
              {
                  var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,t._xscale,100,1,true);
                  var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,t._yscale,100,1,true);
                  var tw3:Tween = new Tween(t,"_x",Strong.easeOut,t._x,100,1,true);
                  var tw4:Tween = new Tween(t,"_y",Strong.easeOut,t._y,200,1,true);
                  var tw5:Tween = new Tween(theText,"_alpha",Strong.easeOut,0,100,1,true);
                  theText.text = t.content;
                  var s:Object = this;
                  tw.onMotionStopped = function()
                  {
                      s.onRelease = unReleased;
                  }
              }
          }
      }

       

       

       

      function unReleased()
      {
          var sou:Sound = new Sound();
          sou.attachSound("sdown");
          sou.start();
         
          delete this.onRelease;
          var tw:Tween = new Tween(theText,"_alpha",Strong.easeOut,100,0,0.5,true);
          for(var i=0;i<numOfItems;i++)
          {
              var t:MovieClip = home["item"+i];
              if(t != this._parent)
              {
                  var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,0,t.theScale,1,true);
                  var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,0,t.theScale,1,true);
                  var tw3:Tween = new Tween(t,"_alpha",Strong.easeOut,0,100,1,true);
              }
              else
              {
                  var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,100,t.theScale,1,true);
                  var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,100,t.theScale,1,true);
                  var tw3:Tween = new Tween(t,"_x",Strong.easeOut,t._x,t.xPos,1,true);
                  var tw4:Tween = new Tween(t,"_y",Strong.easeOut,t._y,t.yPos,1,true);
                  tw.onMotionStopped = function()
                  {
                      for(var i=0;i<numOfItems;i++)
                      {
                          var t:MovieClip = home["item"+i];
                          t.icon.onRollOver = Delegate.create(t.icon,over);
                          t.icon.onRollOut = Delegate.create(t.icon,out);
                          t.icon.onRelease = Delegate.create(t.icon,released);
                          t.onEnterFrame = mover;
                      }
                  }
              }
          }
      }

       


      function moveTip()
      {
          home.tooltip._x = this._parent._x;
          home.tooltip._y = this._parent._y - this._parent._height/2;
      }

       

      xml.load("icons.xml");

       


      function mover()
      {
          this._x = Math.cos(this.angle) * radiusX + centerX;
          this._y = Math.sin(this.angle) * radiusY + centerY;
          var s = (this._y - perspective) /(centerY+radiusY-perspective);
          this._xscale = this._yscale = s*100;
          this.angle += this._parent.speed;
          this.swapDepths(Math.round(this._xscale) + 100);
      }

       

      this.onMouseMove = function()
      {
          speed = (this._xmouse-centerX)/8000;
      }
      // inactive mouse time (in seconds) to start slowing the carousel

       

      var inactiveMouseTime:Number =1;

       

      // rate of slowing carousel;

       

      var speedDamp:Number = .4;

       

       

       

      var speedI:Number;

       

      var startSlowTO:Number;

       

       

       

      this.onMouseMove = function(){

       

      clearInterval(speedI);

       

      clearTimeout(startSlowTO);

       

      startSlowTO = setTimeout(startSlowF,inactiveMouseTime);
          speed = (this._xmouse-centerX)/8000;
      }

       

       

       

      function startSlowF(){

       

      clearInterval(speedI);

       

      speedI=setInterval(speedF,2000);

       

      }

       

       

       

      function speedF(){

       

      speed = speedDamp*speed;

       

      if(speed<.1){

       

      clearInterval(speedI);

       

      speed=0;

       

      }

       

      }

       

      Here is an example of how things are loaded from XML:

      <icons>
      <icon image="Denver_test_icon.png" tooltip="Denver Icon Test" header="test header" content="Test Paragraph. Greeked:. Suspendisse condimentum sagittis luctus." />

      </icons>