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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:49:03+00:00 2026-06-16T01:49:03+00:00

lately I’ve been asked to change a small flash app i made to work

  • 0

lately I’ve been asked to change a small flash app i made to work with external callbacks instead of using the embedded buttons.

I tried to automate the process and came up with this function:

    /**
     * Add an External callback for all PUBLIC methods that listen to 'listenerType' in 'listenersHolder'.
     * @param   listenersHolder - the class that holds the listeners we want to expose.
     * @param   listenerType    - a String with the name of the event type we want to replace with the external callback.
     */
    public static function addCallbacksForListeners(listenersHolder:*, listenerType:String):void
    {
        // get the holder description
        var description:XML = describeType(listenersHolder);
        // go over the methods
        for each(var methodXML:XML in description..method)
        {
            // go over the methods parameters
            for each(var parameterXML:XML in methodXML..parameter)
            {
                // look for the requested listener type
                var parameterType:String = parameterXML.@type;
                if (parameterType.indexOf(listenerType) > -1)
                {
                    var methodName:String =  methodXML.@name;
                    trace("Found: " + methodName);
                    // get the actual method
                    var method:Function = listenersHolder[methodName];
                    // add the callback
                    try 
                    {
                        ExternalInterface.addCallback(methodName, method);
                        trace("A new callback was added for " + methodName);
                    } 
                    catch (err:Error)
                    {
                        trace("Error adding callback for " + methodName);
                        trace(err.message);
                    }
                }
            }
        }

before using this function I had to change the listener’s function to Public, add null default parameter and of course remove/hide the visuals.

for example, from :

private function onB1Click(e:MouseEvent):void

to :

public function onB1Click(e:MouseEvent = null):void

add this line to the init/onAddedToStage function:

addCallbacksForListeners(this, “MouseEvent”);

and remove the button from stage or just comment the line that adds it.

My question is: can you find a better/ more efficient way to do that ?
any feedback is welcomed..

  • 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-16T01:49:04+00:00Added an answer on June 16, 2026 at 1:49 am

    Maybe you should make the javascript to call a single method with different functionName param. Then you only need to add one callback and you don’t need to make all those functions public.

    ExternalInterface.addCallback('callback', onCallback);
    
    public function onCallback(res:Object)
    {
        var functionName:String = res.functionName;
        this[functionName]();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lately I have been using reflection to work in my project, and I have
Lately I've been favoring using named pipes (option --enable-named-pipes) in MySQL running on windows,
Lately I've been searching for the best source control technologies for my work projects
Lately I've been writing some JS code using jQuery and JavaScript as it is
Lately as part of my day job I've been learning IBM Rhapsody and using
Lately I have gotten into SNMP agent development and have been using the 30
Lately I have been working on trying facial recognition with the Kinect, using the
Lately, I have been using Automatic Reference Counting in my Objective-C/iOS programs, and have
Lately I've been using XPathDocument and XNavigator to parse an XML file for a
Lately I have been trying my hands on Eclipse IDE for java development. I

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.