views:

58

answers:

3

I have an instance on my stage that I dragged from my library at design time. This instance links to a custom class who's constructor takes an argument.

package
{
    import flash.display.MovieClip;
    import flash.media.Sound;

    public class PianoKey extends MovieClip
    {
        var note:Sound;

        public function PianoKey(note:Sound)
        {
            this.note = note;
        }
    }
}

Obviously, trying to run the the code as is yields the following argument count error:

ArgumentError: Error #1063: Argument count mismatch on PianoKey(). Expected 1, got 0.

Is there any way to set arguments on an instance that has been manually dragged to the stage?

+1  A: 

I think the only way to do this is by making a PianoKey component. This will have component properties that can be set. They're a real pain to set up though.

spender
A: 

Why not use a setter instead?

package
{
    import flash.display.MovieClip;
    import flash.media.Sound;

    public class PianoKey extends MovieClip
    {
        var _note:Sound;

        public function PianoKey()
        {
        }

        public function set note(value:Sound)
        {
            this._note = value;
        }
    }
}
PatrickS
I was hoping to do it all in one shot to simplify the instantiation code, but oh well.
Soviut
+1  A: 

This may help you. Just little changes are required in Custom Class

package
{
    import flash.display.MovieClip;
    import flash.media.Sound;

    public class PianoKey extends MovieClip
    {
        var note:Sound;

        public function PianoKey(note:Sound=null)
        {
            if(note!=null)
            {
              this.note = note;
            } 
        }
    }
}
Muhammad Irfan