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

The Archive Base Latest Questions

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

Object A calls method M of object B , passing it two callbacks for

  • 0

Object A calls method M of object B, passing it two callbacks for two cases: cbYes and cbNo.

B, in turn, performs a web service async call, creating Object C (api) instance with the only callback: method N of B. This callback will decide which of the two callbacks to call.

I store cbYes and cbNo functions as B’s private vars of type Function.

How can I call either callback? They’re not children of B, so syntax B[cbYes](); is not the way. Unreal code example:

class A {
    public function Smth() {
        var instB:B = new B( cbYes, cbNo);
    }
    public function cbYes( e:Event) { doSomething(); }
    public function cbNo( e:Event) { doSomething(); }
}

class B {
    private var _cb1:Function;
    private var _cb2:Function;
    public function B( cb1, cb2) {
        _cb1 = cb1; _cb2 = cb2;
        var worker:C = new C();
        C.apiMethod123( cbAfterCall);
    }
    public function cbAfterCall( Result:*) {
        if( Result = 1) {
            // here I need to call callback from _cb1
        } else {
            // here I need to call callback from _cb2
        }
    }
}

class C {
    private var _Callback:Function;
    public function C() { }
    public function apiMethod123( cb:Function) {
        this._Callback = cb;
        // create a URLLoader or a Loader and do a web service call
    }
    public function urlCallback( e:Event) {
        // parse response
        this._Callback();
    }
}

Ok, while I was putting together this sample code, I realised I already solved this with the api caller worker! 🙂 Got to have more sleep.

AfterQuestion: does this architectural approach seems really wrong? Please advice a better one, or a pattern that suits the system where concurrent asynchronous API calls are used.

  • 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:24:25+00:00Added an answer on June 4, 2026 at 12:24 am

    If you store cbYes and cbNo as member variables inside B. You can call them like normal functions:

    public function foo(cbYes:Function,cbNo:Function):void
    {
        this.cbYes = cbYes;
        this.cbNo = cbNo;
    }
    
    public function bar():void
    {
        cbYes();
    }
    

    Instead of using callbacks like this you can use the event system to achieve the same result. You can create custom events and dispatch the yes/no event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Objective-C uses a sophisticated message-passing system when one object calls a method on another
I have a service method that calls a DAO which then returns an object
Can I dynamically call an object method having the method name as a string?
What happens when you call notifyAll method on an object that is not waiting?
I'm trying to call a Sort method that expects a parameter of type IComparer<object>
For logging purposes, I would like to call the .ToString() method of every object
According to the docs, super(cls, obj) returns a proxy object that delegates method calls
When I call as instance method of a class as follows : object_name.function_name(); how
I'm using Smarty templates which call object methods. I've put the code on a
Is it possible to call a class method of all objects in a list?

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.