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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:14:22+00:00 2026-06-18T09:14:22+00:00

Okay, so I’ve recently been trying to get my head properly around OOP in

  • 0

Okay, so I’ve recently been trying to get my head properly around OOP in AS3. Right now I have a really simple scenario where I’ve got a class, Paddle, which draws a rectangle. In my document class I create two instances of the Paddle class, paddle1 and paddle2.

I’ve also created a property for my Paddle class which I want to change the colour of the rectangle that it draws. I want to be able to adjust this property from the main class. I know I could do this by passing in attributes when instantiating the class but it seems like a property would be a better way, and now I want to know if this is the right way of thinking or not.

main class:

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

    public class Engine extends Sprite 
    {
        private var paddle1:Paddle = new Paddle();
        private var paddle2:Paddle = new Paddle();

        public function Engine() 
        {
            paddle1.x = 30;
            paddle1.color = 0xFF00FF;
            stage.addChild(paddle1);

            paddle2.x = stage.stageWidth - 45;
            paddle2.color = 0xFF0000;
            stage.addChild(paddle2);
        }

    }

}

Paddle class:

package
{
    import flash.display.MovieClip;
    import flash.display.Shape;
    import flash.display.Graphics;
    import flash.events.Event;

    public class Paddle extends MovieClip
    {
        public var color:uint = 0xFFFFFF;

        public function Paddle() 
        {
            var child:Shape = new Shape();
            child.graphics.beginFill(color);
            child.graphics.drawRect(0, 260, 15, 80);
            child.graphics.endFill();
            addChild(child);
        }

    }

}

If changing the properties in this way is not the best way of doing things then of course say so. Otherwise, what am I doing wrong that it doesn’t work? Seems like it’s something to do with the order (by the time the main class changes the colour attribute, it’s already created the rectangle and it’s too late to change it?)

Thanks 😀

EDIT: realised it might help to say what happens when I execute this code. Basically changing the color attribute from the Engine class doesn’t change the colour of the rectangle and they both just stay white (FFFFFF)

  • 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-18T09:14:23+00:00Added an answer on June 18, 2026 at 9:14 am

    The issue you’re having is that when you do:

    new Paddle();
    

    Your constructor code is run. What this means is that the Rectangle has already been drawn with the color defined at the top of the class. You’re then changing the color property after this, which as you can see has no effect.

    I suggest you make a draw() function for your Paddle. It could accept a color and be used to draw the Rectangle. It might look like this:

    public class Paddle extends MovieClip
    {
    
        private var _child:Shape;
    
    
        public function Paddle() 
        {
            _child = new Shape();
            addChild(_child);
        }
    
    
        public function draw(color:uint):void
        {
            _child.graphics.clear();
            _child.graphics.beginFill(color);
            _child.graphics.drawRect(0, 260, 15, 80);
            _child.graphics.endFill();
        }
    
    }
    

    This way provides an advantage which is that you can modify the arguments of draw() to accept dimensions for your Rectangle or other elements that will affect the visuals. This will be cleaner and faster than having to add more properties to the class itself if you decide you want to do this.

    You’re then able to do this:

    var paddle1:Paddle = new Paddle();
    var paddle2:Paddle = new Paddle();
    
    paddle1.draw(0xFF00FF);
    paddle2.draw(0xFF0000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I've been trying to research how to do this and have failed. I
Okay the answer to this may be really simple but I have been searching
Okay, my problem right now is we're trying to write code that will add
Okay, so I have been working on a chat program. Its a WIP doesn't
Okay i've been fighting this system for about 3 days now and googling left
Okay i have seen TouchXML, parseXML, NSXMLDocument, NSXMLParser but i am really confused with
Okay, Now admittedly this sounds like a silly question; But, I actually have a
Okay that title may not have been too clear, I am building a site
Okay, so I am trying to figure out how to get a link href
Okay, so I'm making a table right now for Box Items. Now, a Box

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.