10 Replies Latest reply on May 20, 2010 4:38 AM by beno12345

    UIScrollBar Problem

    beno12345 Level 1

      Hi;

      I take this code directly from an online tutorial:

       

      package
      {
          import fl.controls.UIScrollBar;
          import flash.display.Sprite;
          import flash.text.TextField;
        
          public class test extends Sprite
          {
              private var tf:TextField;
              private var sb:UIScrollBar = new UIScrollBar();
              private var sampleText:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus vestibulum. Praesent in velit. Fusce scelerisque. Nullam fringilla. Aenean ut lacus at mi rutrum elementum. Suspendisse sit amet ligula et ipsum rhoncus sagittis. Aenean quis lacus. Nullam quis lorem. Integer pellentesque dictum lorem. In hendrerit lectus non orci. Sed vestibulum. Maecenas ornare, libero eu laoreet tristique, felis odio tincidunt nibh, et faucibus nibh tellus at metus. In hac habitasse platea dictumst. Nullam aliquam, dolor ut commodo dictum, ante justo dictum nisi, id suscipit elit sapien nec pede."
            
              public function test() {
                  createTextField();
                  assignScrollBar();
              }
              private function createTextField():void {
                  tf = new TextField();
                  tf.width = 200;
                  tf.height = 100;
                  tf.wordWrap = true;
                  tf.multiline = true;
                  tf.border = true;
                  tf.text = sampleText;
                  addChild(tf);          
              }
              private function assignScrollBar():void {
                  sb = new UIScrollBar();
                  sb.move(tf.x + tf.width, tf.y);
                  sb.setSize(sb.width, tf.height);
                  sb.scrollTarget = tf;
                  addChild(sb);          
              }
          }
      }

       

      It throws these errors:

       

      /Users/benocandelon/Sites/Delta Electric/test.as, Line 10    1046: Type was not found or was not a compile-time constant: UIScrollBar.
      /Users/benocandelon/Sites/Delta Electric/test.as, Line 10    1180: Call to a possibly undefined method UIScrollBar.
      /Users/benocandelon/Sites/Delta Electric/test.as, Line 10    1180: Call to a possibly undefined method UIScrollBar.
      /Users/benocandelon/Sites/Delta Electric/test.as, Line 28    1180: Call to a possibly undefined method UIScrollBar.
      /Users/benocandelon/Sites/Delta Electric/test.as, Line 3    1172: Definition fl.controls:UIScrollBar could not be found.

       

      Huh? Why isn't CS5 importing this??

      TIA,

      beno

        • 1. Re: UIScrollBar Problem
          Ned Murphy Adobe Community Professional & MVP

          This is not a CS5 issue.  Anytime you are trying to dynamically add components you need to have those components available in the file's library, just like any other non-code-based object you might want to add dynamically, a copy of one must be in the library.  Drag a UIScrollbar component onto the stage so that it gets placed in the library, then delete it from the stage.

          • 2. Re: UIScrollBar Problem
            beno12345 Level 1

            Where do I find said widget to drag and drop?

            TIA,

            beno

            • 3. Re: UIScrollBar Problem
              Ned Murphy Adobe Community Professional & MVP

              In the top toolbar select Window -> Components.

               

              Usually the components library will be displayed as a separate tab in the library panel when it is selected to be displayed.

              • 4. Re: UIScrollBar Problem
                beno12345 Level 1

                Well, that worked like a charm, Ned! Thanks again

                beno

                • 5. Re: UIScrollBar Problem
                  iBabs2 Level 2

                  Hello,

                   

                  I too was havimg problems with the UIScroll fromthe components, so I wanted to try this code.

                  I put a component in the library, but I get the following error:

                   

                  1037: Packages cannot be nested.

                  • 6. Re: UIScrollBar Problem
                    beno12345 Level 1

                    Whenever I have errors like that, the first thing I do is google (in this case) "as3 1037" to see what pops up. Usually there's a good explanation of the error. In this case, I couldn't pinpoint it; however, you're apparently nesting a package. Could you post your full code?

                    beno

                    • 7. Re: UIScrollBar Problem
                      iBabs2 Level 2

                      Hello,

                      It was exactly the code you posted:

                       

                      package {
                          import fl.controls.UIScrollBar;
                          import flash.display.Sprite;
                          import flash.text.TextField;

                       

                          public class test extends Sprite {
                              private var tf:TextField;
                              private var sb:UIScrollBar = new UIScrollBar();
                              private var sampleText:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus vestibulum. Praesent in velit. Fusce scelerisque. Nullam fringilla. Aenean ut lacus at mi rutrum elementum. Suspendisse sit amet ligula et ipsum rhoncus sagittis. Aenean quis lacus. Nullam quis lorem. Integer pellentesque dictum lorem. In hendrerit lectus non orci. Sed vestibulum. Maecenas ornare, libero eu laoreet tristique, felis odio tincidunt nibh, et faucibus nibh tellus at metus. In hac habitasse platea dictumst. Nullam aliquam, dolor ut commodo dictum, ante justo dictum nisi, id suscipit elit sapien nec pede.";
                              public function test() {
                                  createTextField();
                                  assignScrollBar();
                              }
                              private function createTextField():void {
                                  tf = new TextField();
                                  tf.width = 200;
                                  tf.height = 100;
                                  tf.wordWrap = true;
                                  tf.multiline = true;
                                  tf.border = true;
                                  tf.text = sampleText;
                                  addChild(tf);
                              }
                              private function assignScrollBar():void {
                                  sb = new UIScrollBar();
                                  sb.move(tf.x + tf.width, tf.y);
                                  sb.setSize(sb.width, tf.height);
                                  sb.scrollTarget = tf;
                                  addChild(sb);
                              }
                          }
                      }

                       

                      thanks!

                      babs

                      • 8. Re: UIScrollBar Problem
                        beno12345 Level 1

                        So, what do you have in your fla file? All I have is, when you click the "Properties" tab, under "Publish", I define the "Class" as "test". I call the fla "test.fla" and the as "test.as". Do you have the same?

                        beno

                        • 9. Re: UIScrollBar Problem
                          iBabs2 Level 2

                          Hi Beno,

                          That was it...

                          Well, more than that..I had put the script in my flash file, not a seperate .as file ;-)

                          Slowly gettting to working outside the .fla file.

                          thanks!

                          worked fine!!

                          babs

                          • 10. Re: UIScrollBar Problem
                            beno12345 Level 1

                            Good. Glad to help. I'm new myself. Can relate

                            beno