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

  • SEARCH
  • Home
  • 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 7942987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:08:24+00:00 2026-06-04T00:08:24+00:00

Hi I have a custom class that extends Sprite, that controls positioning on the

  • 0

Hi I have a custom class that extends Sprite, that controls positioning on the stage. I would like the class that manages the stage to be able to take any sprite that is added to the stage and convert it to custom class type, ie wrap it so that the managing class can position a native sprite accordingly.
Does anyone know if it is possible to do something like the following

var managed:managedSprite = new managedSprite(nativeSprite);

where the managedSprite extends the Sprite class? I don’t want to have to composite in a reference to the sprite if at all possible in order to prevent the overhead associated with the managedSprite already extending Sprite.

Is there anyway using reflection (perhaps the commons.reflection library)?

Thanks

  • 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-04T00:08:26+00:00Added an answer on June 4, 2026 at 12:08 am

    You can add an event listener to the stage and use Event.ADDED to get a reference to any display object added anywhere in the display list.

    Then simply type cast if the added item is a subclass of ManagedSprite (BTW, the convention is to start your class names with an uppercase letter):

    stage.addEventListener (Event.ADDED, onAdded); 
    
    function onAdded( ev:Event ):void {
        if (ev.target is ManagedSprite) {
            var managed:ManagedSprite = ManagedSprite( ev.target );
            doStuffWith( managed );
        }
    }
    

    EDIT

    I think I only just understood your question: You are not trying to do an actual type cast – which would require your class hierarchy to be already set up, i.e. you’d have to have extended the ManagedSprite class already – but to add functionality at runtime!

    I would strongly discourage you from trying to do deep copies or such – it will be heavy on performance, depending on how many sprites you are going to add, and you will no longer have your compiler to help you prevent errors.

    Rather, see if you can’t favor composition over inheritance: Create a kind of “proxy” class for the sprite, let’s call it ManagedSpriteProxy, which implements all the methods you would call on ManagedSprite, but forwards all the actual manipulations to its `managedSprite’ property. Then use the event handler I outlined above to create the proxy objects and attach the respective sprites:

    public class ManagedSpriteProxy {
        private var _managedSprite:Sprite;
    
        public function ManagedSpriteProxy( managedSprite:Sprite ) {
            this.managedSprite = managedSprite;
        }
    
        public function get managedSprite():Sprite {
            return _managedSprite;
        }
    
        public function set managedSprite( managedSprite : Sprite ):void {
            _managedSprite = managedSprite;
            setUpAnyHandlersOrWhatever();
        }
    
        private function setUpAnyHandlersOrWhatever():void {
            // Many wonderful things happening
        }
    
        // Many more wonderful things happening via public API
    }
    
    // somewhere else
    
    public class SpriteManager {
        private var _managedSprites:Array = [];
    
        public function SpriteManager() {
            addEventListener( Event.ADDED_TO_STAGE, onAddedToStage );
        }
    
        private function onAddedToStage( ev:Event ):void {
            removeEventListener( Event.ADDED_TO_STAGE );
            stage.addEventListener( Event.ADDED, onAdded );
        }
    
        private function onAdded( ev:Event ):void {
            if( ev.target is Sprite ) {
                addWithProxy( ev.target as Sprite );
            }
        }
    
        private function addWithProxy( sprite:Sprite ) : void {
            var proxy:ManagedSpriteProxy = new ManagedSpriteProxy( sprite );
            _managedSprites.push( proxy );
        }
    
        // Insert here whatever methods used to manage the sprites, 
        // all of them call the proxies instead of the sprites!
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom-made view that extends the View class. I would like 2
I have a custom class that uses boost mutexes and locks like this (only
I have a custom class that I use to build table strings. I would
I have a custom class called NoteView that extends FrameLayout . Previously, I had
I have a custom button class called ImageButton that extends JButton. In it i
I have a custom class that extends Preference that I'm using in conjunction with
I have a class that extends JButton because the custom look and feel I'm
I have custom class that extends WebViewPage that I use as the base for
I have a custom class that extends List which I am using as a
I have my custom class that extends TEdit: TMyTextEdit = class (TEdit) private fFocusNextOnEnter:

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.