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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:06:17+00:00 2026-05-25T15:06:17+00:00

When you call a method of a class inside a callback function, you can

  • 0

When you call a method of a class inside a callback function, you can not use this object.
To call the method, in javascript, I declare that variable, assign this to that, and use that inside the callback to call the method of this.

In actionscript, do I have to do the same way as I do in javascript?

The following code is the example to use that to call a method inside callback.
Are there more simple way in actionscript?

class C {
    private var that:C;

    function C() {
        that = this
    }

    public function f1():void {
        var sp:Sprite = new Sprite;

        sp.addEventListener(MouseEvent.CLICK, function():void {
            this.f2(); // this doesn't work
            that.f2(); // that works
        });
    }

    public function f2():void {
        trace('hello');
    }
}
  • 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-25T15:06:17+00:00Added an answer on May 25, 2026 at 3:06 pm

    Here’s another way to do that:

    package some.package {
        class SomeSprite extends Sprite {
            public function f1():void
            {
                var sprite1:Sprite = new Sprite;
                sprite1.addEventListener(MouseEvent.CLICK,
                    (new Closure(f2, this, ["Hello"], sprite1).handler));
    
                var sprite2:Sprite = new Sprite;
                sprite2.addEventListener(MouseEvent.CLICK,
                    (new Closure(f2, this, ["Bye Bye"], sprite2).handler));
            }
    
            private function f2(message:String):void
            {
                trace(message);
            }
        }
    }
    
    class Closure {
        public var callback:Function;
        public var thisObj:Object;
        public var params:Array;
        public var dispatcher:IEventDispatcher;
        public var cleanAfterCallback:Boolean = true;
    
        function Closure(callback:Function, thisObj:Object, 
            params:Array, dispatcher:IEventDispatcher)
        {
            this.callback = callback;
            this.thisObj = thisObj;
            this.params = params;
            this.dispatcher = dispatcher;
        }
    
        public function handler(e:Event):void
        {
            callback.apply(thisObj, params);
    
            if (cleanAfterCallback)
                dispatcher.removeEventListener(e.type, eventHandler)
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I call self.class.instance_variable_set(@var, ...) from inside a class method, where is that variable
I want to call a validation method inside a shared gwt class that i
Can I call a java class method from inside a flash movie?
I call addNotify() method in class that I posted here. The problem is, that
In Ruby, how do you call a class method from one of that class's
I am trying to use a method inside class, from another class. namespace Crystal.Utilities
I have a method inside of a MooTools class that I want to access
I have a library-provided function that runs a callback after some processing. Inside that
I'm trying to call a method of another class but this causes my app
How do I call method .get_item(Example1()).do_something() in class Base from inside the class Example2

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.