2

I'm using Flash CS4 Professional to build a draggable element. However, whenever I input my code, I get error 1131. Can somebody please tell me what I'm doing wrong?

stop();

class Scrollbar extends Sprite
{
    var value:Number;
    var padding:Number = 5;

    var _textField:TextField;
    var max:Number;
    var min:Number;
    function draggable()
    {
        min = bar_mc.y;
        max = bar_mc.height - Erhu_H3_btn.height;
        Erhu_H3_btn.addEventListener(MouseEvent.MOUSE_DOWN, dragHandle);
    }

    function dragHandle(event:MouseEvent):void
    {
        Erhu_H3_btn.startDrag(false, new Rectangle(0,min,0,max));
        stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    }

    function stopDragging(event:MouseEvent):void
    {
        Erhu_H3_btn.stopDrag();
        stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);
    }

}
15leungjs1
  • 35
  • 8

1 Answers1

2

You should put the codes of Scrollbar class in a separate .as file and then you can declare an instance like this:

import PackageName.Scrollbar;
stop();
var scrollbar:Scrollbar = new Scrollbar();

Scrollbar class located in "PackageName\Scrollbar.as":

package PackageName{
    import flash.display.Sprite;
    public class Scrollbar extends Sprite{
         var value:Number;
         //...
    }

}
null.point3r
  • 1,053
  • 2
  • 9
  • 17
  • Does that mean I have to put that code on a separate file for it to work? If that is the case, can I do that if my file is not a project? – 15leungjs1 Sep 21 '14 at 08:02
  • Yes, You should `import` the .as file first. – null.point3r Sep 21 '14 at 08:05
  • Could you please tell me how to import .as files into my flash file? – 15leungjs1 Sep 21 '14 at 13:45
  • Thank you, you have been very helpful! – 15leungjs1 Sep 22 '14 at 00:07
  • I've modified the code you've given me a little, to this: import flash.display.Sprite; import flash.events.*; public class ProgramBody extends Sprite{ public var value:Number; And the code I put into my Flash program is this: import Project.ProgramBody; stop(); var ProgramBody:ProgramBody = new ProgramBody(); Is there something wrong with my code? PS. I'm really sorry for bothering you again! – 15leungjs1 Sep 25 '14 at 07:41