Skip to main content
sergey_landar
Inspiring
June 2, 2010
Question

delete scroller from other class

  • June 2, 2010
  • 1 reply
  • 694 views

Hi.

I have FlashSite class where after clicking to button i see page with text and with scroll.

If i click to 'close' button i want removeChild this page, text and scroll.

But for scroll i use code from other class. (i insert this class like: import classes.Scroller.*;)

So, how i can remove this scroller?

code:

public function lilyContent():void
          {
               // create a sample pane
               addChild(lilyPageScroll);
               lilyPageScroll.x = 360;
               lilyPageScroll.y = 400;
               // then attach a new scroller to the pane
               var lilyScroller = new Scroller(lilyPageScroll, lilyPageScroll.width, 540, new scrollerFace(),"vertical");
          }

i use this line:

var lilyScroller = new Scroller(lilyPageScroll, lilyPageScroll.width, 540, new scrollerFace(),"vertical");

to add scroller.

all code for FlashSite class:

package
{
     import flash.display.*;
     import flash.text.*;
     import flash.events.*;
     
     import classes.Scroller.*;
     
     
     public class FlashSite extends MovieClip 
     {
          var lilyDeskBack:LilyDescriptionBackground = new LilyDescriptionBackground();
          var lilyPageScroll = new LilyContent();
          
          //constructor
          public function FlashSite()
          {
               stop();
               addEventListener(Event.ENTER_FRAME, flashSiteLoading);
          }
          
          public function flashSiteLoading(event:Event)
          {
               var mcBytesLoaded:int=this.root.loaderInfo.bytesLoaded;
               var mcBytesTotal:int=this.root.loaderInfo.bytesTotal;
               var mcKLoaded:int=mcBytesLoaded/1024;
               var mcKTotal:int=mcBytesTotal/1024;
               flashSiteLoading_txt.text="Loading: "+mcKLoaded+"Kb of "+mcKTotal+"Kb";
               if (mcBytesLoaded>=mcBytesTotal)
               {
                    removeEventListener(Event.ENTER_FRAME, flashSiteLoading);
                    gotoAndPlay('welcomeSite');
                    
                    lilyBtn.addEventListener(MouseEvent.CLICK, lilyDescription);
                    roseBtn.addEventListener(MouseEvent.CLICK, roseDescription);
                    jasmineBtn.addEventListener(MouseEvent.CLICK, jasmineDescription);
                    irisBtn.addEventListener(MouseEvent.CLICK, irisDescription);
                    
               }
          }
          public function lilyDescription(event:MouseEvent):void
          {
               trace("Lily description goes here.");
               roseBtn.visible = false;
               jasmineBtn.visible = false;
               irisBtn.visible = false;
               
               addChild(lilyDeskBack);
               lilyDeskBack.x = 350;
               lilyDeskBack.y = 330;
               lilyContent();
               
               lilyDeskBack.LilyDesckClose_btn.addEventListener(MouseEvent.CLICK, closeLilyDescription);
          }
          public function closeLilyDescription(event:MouseEvent):void
          {
               trace("close Lily description");
               removeChild(lilyDeskBack);
               removeChild(lilyPageScroll);
               lilyScroller.visible = false;
               
               roseBtn.visible = true;
               jasmineBtn.visible = true;
               irisBtn.visible = true;
          }
          public function roseDescription(event:MouseEvent):void
          {
               trace("Rose description goes here.");
          }
          public function jasmineDescription(event:MouseEvent):void
          {
               trace("Jasmine description goes here.");
          }
          public function irisDescription(event:MouseEvent):void
          {
               trace("Iris description goes here.");
          }
          
          public function lilyContent():void
          {
               // create a sample pane
               addChild(lilyPageScroll);
               lilyPageScroll.x = 360;
               lilyPageScroll.y = 400;
               // then attach a new scroller to the pane
               var lilyScroller = new Scroller(lilyPageScroll, lilyPageScroll.width, 540, new scrollerFace(),"vertical");
          }
          
     }
     
}




Thanks for help

This topic has been closed for replies.

1 reply

Inspiring
June 2, 2010

Make the lilyScroller object a class level object.

Add to 'closeLilyDescription' method 'removeChild(lilyScroller);'

package 
{
     import flash.display.*;
     import flash.text.*;
     import flash.events.*;
    
     import classes.Scroller.*;
    
    
     public class FlashSite extends MovieClip 
     {
          var lilyDeskBack:LilyDescriptionBackground = new LilyDescriptionBackground();
          var lilyPageScroll = new LilyContent();
          var lilyScroller;
         
          //constructor
          public function FlashSite()
          {
               stop();
               addEventListener(Event.ENTER_FRAME, flashSiteLoading);
          }
         
          public function flashSiteLoading(event:Event)
          {
               var mcBytesLoaded:int=this.root.loaderInfo.bytesLoaded;
               var mcBytesTotal:int=this.root.loaderInfo.bytesTotal;
               var mcKLoaded:int=mcBytesLoaded/1024;
               var mcKTotal:int=mcBytesTotal/1024;
               flashSiteLoading_txt.text="Loading: "+mcKLoaded+"Kb of "+mcKTotal+"Kb";
               if (mcBytesLoaded>=mcBytesTotal)
               {
                    removeEventListener(Event.ENTER_FRAME, flashSiteLoading);
                    gotoAndPlay('welcomeSite');
                   
                    lilyBtn.addEventListener(MouseEvent.CLICK, lilyDescription);
                    roseBtn.addEventListener(MouseEvent.CLICK, roseDescription);
                    jasmineBtn.addEventListener(MouseEvent.CLICK, jasmineDescription);
                    irisBtn.addEventListener(MouseEvent.CLICK, irisDescription);
                   
               }
          }
          public function lilyDescription(event:MouseEvent):void
          {
               trace("Lily description goes here.");
               roseBtn.visible = false;
               jasmineBtn.visible = false;
               irisBtn.visible = false;
              
               addChild(lilyDeskBack);
               lilyDeskBack.x = 350;
               lilyDeskBack.y = 330;
               lilyContent();
              
               lilyDeskBack.LilyDesckClose_btn.addEventListener(MouseEvent.CLICK, closeLilyDescription);
          }
          public function closeLilyDescription(event:MouseEvent):void
          {
               trace("close Lily description");
               removeChild(lilyDeskBack);
               removeChild(lilyPageScroll);
               removeChild(lilyScroller);
               lilyScroller.visible = false;
              
               roseBtn.visible = true;
               jasmineBtn.visible = true;
               irisBtn.visible = true;
          }
          public function roseDescription(event:MouseEvent):void
          {
               trace("Rose description goes here.");
          }
          public function jasmineDescription(event:MouseEvent):void
          {
               trace("Jasmine description goes here.");
          }
          public function irisDescription(event:MouseEvent):void
          {
               trace("Iris description goes here.");
          }
         
          public function lilyContent():void
          {
               // create a sample pane
               addChild(lilyPageScroll);
               lilyPageScroll.x = 360;
               lilyPageScroll.y = 400;
               // then attach a new scroller to the pane
               lilyScroller = new Scroller(lilyPageScroll, lilyPageScroll.width, 540, new scrollerFace(),"vertical");
          }
         
     }
    
}
sergey_landar
Inspiring
June 3, 2010

i made it, but 'removeChild(lilyScroller);' not help