2 Replies Latest reply on Jun 23, 2011 8:19 AM by mentlity

    Editing an .as file

    mentlity Level 1

      I need to add a scrolling movieclip to a Flash animation. Would have been nice to use the scrollbar component but I have to use custom scroll buttons for this one.

       

      I found a similar fla that has an .as file attached and it has what I'm looking for but instead of scrolling a movieclip it scrolls a text box.

       

      I know basic as and was wondering if someone could show me how to re code and replace the text box with a movieclip so I do not get any errors in the file.

       

      as code is below

       

      package {
         
          import flash.display.MovieClip;
          import flash.events.Event;
          import flash.events.MouseEvent;
          import flash.text.TextFieldAutoSize;
         
          public class TextBox extends MovieClip {
             
              // text will scroll with speed of 8 pixels per frame
              private var scrollSpeed:Number = 8;
             
              // scroll direction:
              // 0 no scroll
              // 1 up
              // -1 down
              private var scrollDirection:Number;
             
              public function TextBox() {
                 
                  upButton.addEventListener(MouseEvent.MOUSE_DOWN, handleScrollUp);
                  upButton.addEventListener(MouseEvent.MOUSE_UP, handleStopScroll);
                  // this line change cursor to hand
                  upButton.buttonMode = true;
                 
                  downButton.addEventListener(MouseEvent.MOUSE_DOWN, handleScrollDown);
                  downButton.addEventListener(MouseEvent.MOUSE_UP, handleStopScroll);
                  downButton.buttonMode = true;
                 
                 
                  var htmlText:String = '<font size="+2" color="#FF0000"><b>Header Header Header Header Header Header Header</b></font><br><br>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text';
                 
                 
                  textContainer.text.wordWrap = true;
                 
                  // text field height will grow depending of the text height
                  textContainer.text.autoSize = TextFieldAutoSize.LEFT;
                 
                  // set text field html text
                  textContainer.text.htmlText = htmlText;
                 
                 
              }
             
              private function handleScrollUp(event:MouseEvent):void {
                 
                  scrollDirection = 1;
                 
                  // handleEnterFrame will be called with FPS frequency
                  addEventListener(Event.ENTER_FRAME, handleEnterFrame);
                 
              }
             
              private function handleScrollDown(event:MouseEvent):void {
                 
                  scrollDirection = -1;
                 
                  addEventListener(Event.ENTER_FRAME, handleEnterFrame);
              }
             
              private function handleStopScroll(event:Event):void {
                 
                  scrollDirection = 0;
                 
                  removeEventListener(Event.ENTER_FRAME, handleEnterFrame);
              }
             
              private function handleEnterFrame(event:Event):void {
                 
                  // calculating text container Y value
                  var textContainerY:Number = textContainer.y + scrollDirection * scrollSpeed;
                 
                  if (textContainerY > textMask.y) {
                     
                      textContainerY = textMask.y;
                  }
                  else if (textContainerY + textContainer.height < textMask.y + textMask.height) {
                     
                      textContainerY = textMask.y + textMask.height - textContainer.height;
                  }
                 
                  // set text scroll value
                  textContainer.y = textContainerY;
                 
              }
             
             
          }
         
         
      }

       

      thx

      rd