Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 938089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:35:06+00:00 2026-05-15T21:35:06+00:00

package com.adam.etutorial { import flash.display.MovieClip; import flash.text.TextField; import flash.display.Sprite; import flash.text.TextFormat; import flash.display.Shape; public

  • 0
package com.adam.etutorial

{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.display.Sprite;
import flash.text.TextFormat;
import flash.display.Shape;

public class adamsboxmaker
{

    //(boxWidth, boxHeight, lineColour, lineThickness, beginFillColour, fillIf, fontcolour, fontsize, fonttype, textFormat, textWidth, textHeight, text, Xoffset, Yoffset, textIf)
    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)
    {

        createBox(boxWidth,boxHeight,lineColour,lineThickness, beginFillColour, fillIf, fontColour, fontSize, fontType, textWidth, textHeight, txt, Xoffset, Yoffset, textIf);


    }

    private 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)
    {


        /*BUILD CONTAINER*/
        var container:MovieClip = new MovieClip();
        /*END CONTAINER*/

        /*BUILD BOX*/
        var theBox:Shape = new Shape();
        container.addChild(theBox);
        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*/
        }
        container.visible = false;

    return container;

    }

}

}

This is my first crack at writing a class and after reading up this is what I have.

Essentially, I want to be able to write var txt:adamsboxmaker = new adamsboxmaker(parameters);

and have txt be a display object from the returned MovieClip. But that’s not happening.
Can someone point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:35:06+00:00Added an answer on May 15, 2026 at 9:35 pm

    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.

    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

     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){
    

    and remove the call from inside the constructor.

    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
    
    }
    

    Then all you need to do is

    txt = adamsboxmaker.createBox(paramters);
    

    Re: Question in comment

    In this case you want your adamsboxmaker to be the box. So first make the class extend MovieClip

    public class adamsboxmaker extends MovieClip
    {
    

    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:

          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;
         }
    

    Now you can go

    txt = new adamsboxmaker(parameters);
    addChild(txt);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.