1
votes

There is a library component represented by Class A. But constructor of this class requires some parameters. When the component needs to be added dynamically, it's fine because of code :

var abc:A = new A(param1,param2)

But what if my movieclip is already present on the stage. I notice it gives out error, that the parameters are null.

Is their any way to insert constructor parameters for movieclips already on stage.

Thanks

2

2 Answers

2
votes

Vishwas, any symbols on the stage have already been instantiated. You cannot call their constructor again. Instead, try writing a public function in those classes that sets up the variables that you need. Internally, if those variables are not set, you can toggle the visibility to false and wait, or just not process anything. Once they are set, your clips are off and running again.

Then, in addition to calling the public function on the clips on the stage, you can add optional parameters to the constructor for those instances you'll create via code, not the Flash IDE. If the parameters exist in the constructor, just go ahead and call the function right there.

public function Constructor ( var1:String = '', var2:MovieClip = null) {
    if (var1 && var2) init (var1, var2);
}

public function init (var1:String, var2:MovieClip) {
    ...
}
0
votes

You can set default parameters in constructor, for example:

function A(param1:String = "default", param2:int=5):void {

}

Then movie clips added to stage will use these default values, but you can use different parameters in dynamically created components.