Reputation: 9049
The following is my constructor class, however when I try to add the argument when I instantiate my object, I get an error saying I have no default constructor. I basically want to pass a string to the object, but not all objects will get a string.
public function Shortcuts(opencontent:String){
highlight = new shortcuthighlight();
highlight.x = highlight.x - highlight.width/2;
highlight.y = highlight.y - highlight.height/2;
highlight.visible = false;
addChild(highlight);
setChildIndex(highlight,0);
this.addEventListener(MouseEvent.ROLL_OVER, addHighlight);
this.addEventListener(MouseEvent.ROLL_OUT, removeHighlight);
this.addEventListener(MouseEvent.MOUSE_DOWN, dragOn);
this.addEventListener(MouseEvent.MOUSE_UP, dragOff);
}
Here is how I create my objects.
for(var i=0; i<shortcutsArray.length;i++){
var className:Class = getDefinitionByName(shortcutsArray[i][0]) as Class;
var object:Object = new className('hey');
var mc:MovieClip = MovieClip(object);
mc.x = shortcutsArray[i][1];
mc.y= shortcutsArray[i][2];
addChild(mc);
}
Upvotes: 0
Views: 285
Reputation: 15955
If you mean you want opencontent
to be optional, you can set a default parameter:
public function Shortcuts(opencontent:String=null)
{
/* ... */
}
Upvotes: 2