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 9148041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:09:52+00:00 2026-06-17T11:09:52+00:00

I’m attempting to write a program in ActionScript 3 using the Flex library and

  • 0

I’m attempting to write a program in ActionScript 3 using the Flex library and the FlashDevelop IDE. The program needs to have five blank squares drawn on the stage, and clicking on any of those squares will independently render a unique pattern (made up of geometic primitives) that takes the place of that square. Clicking on those patterns again will will switch them back to blank squares.

I decided to abstract this behavior into a a user-defined class that was an extension of Sprite, called PatternTile. However, I am getting a procedural error where the PatternTile itself isn’t visible despite being added to the stage (confirmed by an event handler). The object by default should render in the center stage, and according to the parameters there should at least be a black outline around a rectangle. When clicked on, the object is supposed to redraw itself by way of clearing and respecifying the graphics properties.

There is an argument for the constructor that switches what properties these will be. Right now they are all equivalent.

Below is the code of the PatternTile class:

package  
{
    /**
     * ...
     * @author ...
     */

    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;

    public class PatternTile extends Sprite
    {
        // OBJECTIVE: Generalize a tile object that can be drawn several times independently and change pattern when clicked.

        // DECLARE+INSTANCE VARS

        private var tileFlip : Boolean = new Boolean( true ) ; // tileFlip - switch for tracking state of shape when clicked on

        // PatternTile, for the sake of simplicity, will include all its potential shapes in its constructor.
        private var patternCode : int = new int(  ); // Stores pattern classification to switch what the pattern for this tile is.

        // CONSTRUCTOR
        public function PatternTile( xBase:int, yBase:int, xTrans:int , yTrans:int , patternType:int ):void
        {

            /* ARGUMENTS:
             * xBase - reference point for translations on the X axis.
             * yBase - reference point for translations on the Y axis.
             * xTrans:int - integer representing displacement of pixels from center on X axis. 
             * yTrans:int - integer representing displacement of pixels from center on Y axis. 
             * patternType:int - sets code for pattern
             */

            patternCode = patternType

            x = xBase + xTrans ; // x - new X position

            y = yBase + yTrans ; // y - new Y position

            // Assign Parametres to blankTile
            this.graphics.lineStyle( 5, 0x000000, 1)
            this.graphics.beginFill( 0xFFFFFF, 1 );
            this.graphics.drawRect( x , y , 200 , 200 );
            this.graphics.endFill(  );

            // EVENT LISTENERS - Clicking on the Sprite
            addEventListener( MouseEvent.CLICK , mouseClickHandler ); // Will this generalize to handling clicks on both pattern types (tile, altObject?); 
            addEventListener( Event.ADDED_TO_STAGE, addedToStage ); // Created event handler for debugging purposes.
        }

        // Mouse Click Function
        public function mouseClickHandler(event:Event):void
        {
            if (tileFlip) {

                this.graphics.clear(); // clear previous properties

                switch (patternCode) {
                // Because I know there are only five cases, I can include all of them within the object.
                    case 0: // Pattern 0

                        // Colour Properties
                        this.graphics.lineStyle( 1, 0x000000, 1 );
                        this.graphics.beginFill(0xFFFFFF, 1);
                        // Draw shape primitives here
                        this.graphics.drawCircle( x, y, 50 ); // PLACEHOLDER
                        this.graphics.endFill(  );
                        // trace("you are here")

                        break;

                    case 1: // Pattern 1

                        // Colour Properties
                        this.graphics.lineStyle( 1, 0x000000, 1 );
                        this.graphics.beginFill(0xFFFFFF, 1);
                        // Draw shape primitives here
                        this.graphics.drawCircle( x, y, 50 ); // PLACEHOLDER
                        this.graphics.endFill(  );

                        break;

                    case 2: // Pattern 2

                        // Colour Properties
                        this.graphics.lineStyle( 1, 0x000000, 1 );
                        this.graphics.beginFill(0xFFFFFF, 1);
                        // Draw shape primitives here
                        this.graphics.drawCircle( x, y, 50 ); // PLACEHOLDER
                        this.graphics.endFill(  );

                        break;

                    case 3: // Pattern 3

                        // Colour Properties
                        this.graphics.lineStyle( 1, 0x000000, 1 );
                        this.graphics.beginFill(0xFFFFFF, 1);
                        // Draw shape primitives here
                        this.graphics.drawCircle( x, y, 50 ); // PLACEHOLDER
                        this.graphics.endFill(  );

                        break;

                    case 4: // Pattern 4

                        // Colour Properties
                        this.graphics.lineStyle( 1, 0x000000, 1 );
                        this.graphics.beginFill(0xFFFFFF, 1);
                        // Draw shape primitives here
                        this.graphics.drawCircle( x, y, 50 ); // PLACEHOLDER
                        this.graphics.endFill(  );

                        break;

                    }

                tileFlip = false; // prime alternate state to be checked on next click

            } else {

                this.graphics.clear(); // clear previous properties         

                // Blank Tile Properties
                this.graphics.lineStyle( 1, 0x000000, 1 );
                this.graphics.beginFill(0xFFFFFF, 1);
                this.graphics.drawRect( x , y , 100 , 100 );
                this.graphics.endFill(  );

                tileFlip = true; // prime alternate state to be checked on next click
            }
        }

        public function addedToStage(e:Event):void 
        {
             trace("Added PatternTile to stage");           
        }

    }
}

And below is the Main class:

package 
{
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;

    // User-Defined Classes
    import PatternTile

    /**
     * ...
     * @author kbruskie
     */
    public class Main extends Sprite 
    {
        // Center Stage, called throughout program.
        private var xCenter : int = new int( stage.stageWidth / 2 );
        private var yCenter : int = new int( stage.stageHeight / 2 );

        // Tiles
        private var tile1 : PatternTile ;
        /*      
        private var tile2 : PatternTile = new PatternTile( 0, 0, 0 );
        private var tile3 : PatternTile = new PatternTile( 0, 0, 0 );   
        private var tile4 : PatternTile = new PatternTile( 0, 0, 0 );   
        private var tile5 : PatternTile = new PatternTile( 0, 0, 0 );
        */

        public function Main():void 
        {
            trace(xCenter) // prints center of stage on X axis - working
            trace(yCenter) // prints center of stage on Y axis - working

            tile1 = new PatternTile( xCenter, yCenter, 200, -200, 1 ) // draws single clickable tile in the middle of the stage. Not yet added to stage.
            // instances the object but it isn't visibly drawn. What's going on?

            stage.addChild(tile1) // Finally - all the properties are set, and this object is ready for showbiz. Add to stage.
        }
    }
}

I don’t understand what is happening and I am not confident in my theories. Can anyone help?

  • 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-06-17T11:09:55+00:00Added an answer on June 17, 2026 at 11:09 am

    I am assuming that your objects are on the stage, but outside the visible area… In PatternTile constructor you are setting position, eg:

    x = xBase + xTrans;
    

    Then you are drawing a square starting at x:

    this.graphics.drawRect( x , y , 200 , 200 );
    

    So square is effectively drawn at position x+x. Shouldnt it be this?

    this.graphics.drawRect( 0 , 0 , 200 , 200 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am using JSon response to parse title,date content and thumbnail images and place
I have a small JavaScript validation script that validates inputs based on Regex. I

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.