Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok. So the problem here is a little misunderstanding. You are creating an instance of a adamsboxmaker class and the reference is then automatically returned and stored in the txt variable. This is how Object Orientated languages work.</p> <p>What you are trying to do is use a factory method to create an object. To implement this, change your createBox to a public static function </p> <pre><code> public static function createBox(boxWidth:Number,boxHeight:Number,lineColour:Number,lineThickness:int, beginFillColour:Number, fillIf:Boolean, fontColour:Number, fontSize:int, fontType:String, textWidth:Number, textHeight:Number, txt:String, Xoffset:Number, Yoffset:Number, textIf:Boolean){ </code></pre> <p>and remove the call from inside the constructor. </p> <pre><code>public function adamsboxmaker(boxWidth:Number,boxHeight:Number,lineColour:Number,lineThickness:int, beginFillColour:Number, fillIf:Boolean, fontColour:Number, fontSize:int, fontType:String, textWidth:Number, textHeight:Number, txt:String, Xoffset:Number, Yoffset:Number, textIf:Boolean) { //removed call } </code></pre> <p>Then all you need to do is </p> <pre><code>txt = adamsboxmaker.createBox(paramters); </code></pre> <p><strong>Re: Question in comment</strong></p> <p>In this case you want your adamsboxmaker to be the box. So first make the class extend MovieClip</p> <pre><code>public class adamsboxmaker extends MovieClip { </code></pre> <p>You can now consider the instance of this class to be the same as the container:MovieClip you were creating. Add this code into the constructor:</p> <pre><code> public function adamsboxmaker(boxWidth:Number,boxHeight:Number,lineColour:Number,lineThickness:int, beginFillColour:Number, fillIf:Boolean, fontColour:Number, fontSize:int, fontType:String, textWidth:Number, textHeight:Number, txt:String, Xoffset:Number, Yoffset:Number, textIf:Boolean){ var theBox:Shape = new Shape(); addChild(theBox); //we add it to this, rather than a container theBox.graphics.lineStyle(lineThickness, lineColour); if (fillIf == true) { theBox.graphics.beginFill(beginFillColour); } theBox.graphics.moveTo(0, 0); theBox.graphics.lineTo(boxWidth, 0); theBox.graphics.lineTo(boxWidth, boxHeight); theBox.graphics.lineTo(0, boxHeight); theBox.graphics.lineTo(0, 0); if (fillIf == true) { theBox.graphics.endFill(); } /*END BOX*/ if (textIf == true) { /*BUILD FORMATTING*/ var myFormat:TextFormat = new TextFormat(); myFormat.color = fontColour; myFormat.size = fontSize; myFormat.font = fontType; /*END FORMATTING*/ /*BUILD TEXTFIELD*/ var theText:TextField = new TextField(); theText.text = txt; theText.x = Xoffset; theText.y = Yoffset; theText.width = textWidth; theText.height = textHeight; theText.wordWrap = true; theText.setTextFormat(myFormat); container.addChild(theText); /*END TEXTFIELD*/ } visible = false; } </code></pre> <p>Now you can go </p> <pre><code>txt = new adamsboxmaker(parameters); addChild(txt); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload