質問

I am trying to convert someone else's flash application to ActionScript 3. I've never had to deal with ActionScript before now. I've tried to do what the error messages tell me to but they are running me in circles. So here is a simplified version of the situation. I have an action script in the base folder that looks like this:

class IF12345
{
    var a0:controls.Button;
    var a1:controls.TextArea;
    var a2:controls.TextInput;
}

Now the controls look like this:

dynamic class mx.controls.Button extends mx.controls.SimpleButton
{
    var enabled;
    function Button()
    {
    }
    function draw()
    {
    }

    var borderW = 1;
}

First error I got was it complaining that an action script must have one externally visible class so I added public to the class in the base file. Then it said you can't have a public class without a package so I wrapped it in a package.

After that it said that an action script must have one externally visible class for a control so I added public to the control class. Of course it then complained about needing to be in a package but then when I put the control class in a package it said I can't have a nested package. So at this point I don't know what to do?

役に立ちましたか?

解決

Looks like you're mixed up on a few points, but the main one I see is it looks like you're trying to make the class name include the entire package. A working example of what I think you want would be:

package controls
//      ^^^^^^^^ The controls package is defined here, not when providing the
//               class name like in your example.
{
    import flash.display.SimpleButton;
    //     ^^^^^^^^^^^^^ In ActionScript 3, SimpleButton is in the
    //                   flash.display package, and needs to be imported with an
    //                   import statement above the class definition.

    public class Button extends SimpleButton
    //           ^^^^^^ We only use the class name here. You can do the fully
    //                  qualified class name for the extended class, but the
    //                  import statement is cleaner and makes that unnecessary
    //                  except for in uncommon circumstances.
    {
        private var enabled:Boolean = false;
        private var borderW:int = 1;

        public function Button()
        {
            // Constructors must be public.
        }

        public function draw()
        {
            //
        }
    }
}

And your other class:

package
{
    import controls.Button;
    //     ^^^^^^^^^^^^^^^ Need to import your above Button class.

    public class IF12345
    {
        public var a0:Button;
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top