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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:58:55+00:00 2026-06-15T14:58:55+00:00

Simple enough. If I have a container class that holds a Sprite object, and

  • 0

Simple enough.

If I have a container class that holds a Sprite object, and I attach a touch listener to said Sprite, is there a reliable and cheap method of getting the object that contains the Sprite when it is touched? I realize I could just inherit the Sprite, but that is not what I want to do.

Failing that, if I add the event listener to said Sprite object within the class that contains it, is there a way to dispatch an event that would allow me to get the reference to the container that holds the Sprite object that was touched?

Thanks for any help.

Reply to loxxxy:

When I said “held”, I meant in terms of aggregation. For example:

public class Container 
    {
        [Embed(source = "img1.jpg")] private var img:Class;

        private var sprite:Sprite;
        private var bitmap:Bitmap;

        public function Container() 
        {
            bitmap = new img();
            sprite = new Sprite();
            sprite.addChild(bitmap);
        }

        public function GetSprite():Sprite
        {
            return sprite;
        }

    }

Which is perfectly legal code. What I wanted to do was, when the Sprite object is touched outside of the Container class, that I could access other properties within the Container class through said Sprite object. However, a solid workaround would be something like the following, I think:

public class Container extends InteractiveDisplayObject
    {
        [Embed(source = "img1.jpg")] private var img:Class;

        private var bitmap:Bitmap;

        public function Container() 
        {
            bitmap = new img();
this.addChild(bitmap);

        }
    }

Then, I could access the aggregate objects of the Container class by listening to touch events on the Container class, while making it fully extendable to any other DisplayObject class (TextField, Sprite, etc.).

There’s a very specific reason I want to do this, I just don’t feel it’s relevant to the actual question. I’ll try this approach when I get some time to test it out, and see how it goes. 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-15T14:58:57+00:00Added an answer on June 15, 2026 at 2:58 pm

    You don’t really need to dispatch events just for this purpose.

    Add the event listener to the container & you can get reference to both container & sprite. For eg:

    container.addEventListener(MouseEvent.CLICK, container_touched, false, 0, true);
    
    function container_touched(e) { 
    
        trace(e.target.name);            // Output : sprite
        trace(e.currentTarget.name);     // Output : container
    }
    

    EDIT :

    Or you could have rather exposed the sprite event to others by adding a function like :

    public function registerCallback( callback:Function) {
    
        var thisRef = this; 
    
        sprite.addEventListener(MouseEvent.CLICK, function(e) {
    
             callback(thisRef);
    
        },false, 0, true);    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple three table reference. It looks plain enough. The associations there
Seems simple enough. I'm creating a search engine that returns results to the user
That seems simple enough, but all Django Queries seems to be 'SELECT *' How
I have a fairly simple system, and for the purposes of this question there
I have put together a simple ASP.NET MVC 3 test web app that uses
I have a C# interface, and a concrete class that implements that interface. I
I have a custom Vector class that contains an x, y, and z. These
I have an abstract class called Node . It contains a constructor that takes
Probably a simple enough questions for you CSS buffs: I have a simple unordered
In my test code, I have a simple div that I'm using as a

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.