A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Force Remove Objects From Stage

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    17

    resolved [RESOLVED] Force Remove Objects From Stage

    Hi Guys,

    I am using a carousel (from Lee Brimelowe's tutorial) as the main method of navigation from my site's homepage. There are six icons in the carousel, clicking any one brings the icon to the front and some dynamic text and a button to navigate to a different page appear on stage. Clicking the icon again brings the icon back to the carousel and the text and button disappear.

    The site is multi-lingual (English, German, Dutch, Polish) and all text changes to the relevant language by clicking a flag button, including the text that appears beside the 'expanded' carousel icon - all of the data is loaded from XML files.

    The problem with changing the language is that the entire carousel needs to be destroyed and rebuilt each time, as all of the data needed for it is only loaded on runtime. I have this 'kinda' working, the problem I am having is:

    If you change the language via a flag button when an icon is 'expanded' the dynamic text and button (theText and urlBtn) get 'stuck' on the stage and you have to do some clicking on the new carousel icons remove them - not ideal!

    Can anybody out there please advise me on how I would include some AS to remove these items too when the language button is changed?

    The AS that I am using is here:

    Actionscript Code:
    import mx.utils.Delegate;
        import mx.transitions.Tween;
        import mx.transitions.easing.*;

        var numOfItems:Number;
        var radiusX:Number = 300;
        var radiusY:Number = 75;
        var centerX:Number = Stage.width / 2;
        var centerY:Number = Stage.height / 1.8;
        var speed:Number = 0.05;
        var perspective:Number = 130;
        var home:MovieClip = this;
        theText._alpha = 0;
        urlBtn._alpha = 0;
        var carouselClips:Array = new Array;//<< array of clips in the carousel
        var currentCarousel:Number = 1;//<<Keeps track of which XML is loaded
       
        var tooltip:MovieClip = this.attachMovie("tooltip","tooltip",10000);
        tooltip._alpha = 0;

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

        xml.onLoad = function()
        {
           for (z=0; z<carouselClips.length; z++) {//<< loop through all clips in the array
              removeMovieClip(carouselClips[z]);//<< delete them
           }
           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.url = nodes[i].attributes.url;      
                        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;
              carouselClips.push(t);//<< Push each clip into the array
           }
        }

        function over()
        {
           //BONUS Section
           var sou:Sound = new Sound();
           sou.attachSound("sover");
           sou.start();
           
           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
           var sou:Sound = new Sound();
           sou.attachSound("sdown");
           sou.start();
           
           home.tooltip._alpha = 0;
           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,350,1,true);
                 var tw4:Tween = new Tween(t,"_y",Strong.easeOut,t._y,500,1,true);
                 var tw5:Tween = new Tween(theText,"_alpha",Strong.easeOut,0,100,1,true);
                 theText.text = t.content;
                 
                 urlBtn._alpha = 100;
                 
                 var page = t.url;
                 urlBtn.onRelease = function()
                 {
                    getURL(page, "_blank");
                 }
                 var s:Object = this;
                 tw.onMotionStopped = function()
                 {
                    s.onRelease = unReleased;
                 }
              }
           }
        }

        function unReleased()
        {
           //BONUS Section
           var sou:Sound = new Sound();
           sou.attachSound("sdown");
           sou.start();
           
           urlBtn._alpha = 0;
           
           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;
        }
       
    enBtn.onRelease = function() {

         switch (currentCarousel)
         {
              default:
                   xml.load("carouselicons1.xml");
                   currentCarousel = 1;
                   break;
         }
    }  
    plBtn.onRelease = function() {

         switch (currentCarousel)
         {
              default:
                   xml.load("carouselicons3.xml");
                   currentCarousel = 3;
                   break;
         }
    }
    deBtn.onRelease = function() {

         switch (currentCarousel)
         {
              default:
                   xml.load("carouselicons2.xml");
                   currentCarousel = 2;
                   break;
         }
    }
    nlBtn.onRelease = function() {

         switch (currentCarousel)
         {
              default:
                   xml.load("carouselicons4.xml");
                   currentCarousel = 4;
                   break;
         }
    }

        xml.load("carouselicons1.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)/10000;
        }

    And here is a sample of the 'carouselicons' XML files I am using:

    Actionscript Code:
    <icons>

    <icon image="cam.png" tooltip="Photos" url="http://localhost/Sample.html" content="This is a camera - it is used to take pictures." />

    <icon image="cont.png" tooltip="Contacts" url="http://localhost/Sample.html" content="Contact me!" />

    <icon image="blog.png" tooltip="Ships Log" url="http://localhost/Sample.html" content="Read all about it!" />

    <icon image="skull.png" tooltip="Stuff!" url="http://localhost/Sample.html" content="This is for stuff!" />

    <icon image="tool.png" tooltip="Materials" url="http://localhost/Sample.html" content="This will tell you what we used for buiding the boat." />

    <icon image="vid.png" tooltip="Videos" url="http://localhost/Sample.html" content="Click here for videos of the boat build." />

    </icons>

    Any help much, much appreciated!

    lobster_bot

  2. #2
    Junior Member
    Join Date
    Feb 2010
    Posts
    17

    resolved Resolved

    Hi Everyone,

    The issues I was having in this post were resolved here in a further post. You can check it out here: http://board.flashkit.com/board/showthread.php?t=819784

    Thanks everyone!

    lobster_bot

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center