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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:59:45+00:00 2026-05-16T07:59:45+00:00

I’m attempting to write a performance testing function that can take any function, run

  • 0

I’m attempting to write a performance testing function that can take any function, run it X times and spit out how long it took that function to run in AS3. I’ve got it working just fine if a function doesn’t take any parameters but it comes up with an error otherwise.

Here’s the code:

public static function testFunction(targetFunction : Function, object : Object, ... parameters)
{
    var iterations : int = 10000;
    var i : int = 0;
    var time0 : Number = 0;
    var time1 : Number = 0;

    if (parameters.length == 0)
    {
        time0 = getTimer();

        for (i = 0; i < iterations; ++i)
        {
            targetFunction();
        }

        time1 = getTimer();
    }
    else
    {
        time0 = getTimer();

        for (i = 0; i < iterations; ++i)
        {
            targetFunction.call(object, parameters);
        }

        time1 = getTimer();
    }

    trace("Took " + (time1 - time0) + "ms to complete " + iterations + " iterations");
}

This works just fine:
testFunction(timelineMethod)

But something like this:
testFunction(game.addGameState, game, gameState); // gameState would be the parameters

throws this:
TypeError: Error #1034: Type Coercion failed: cannot convert []@2f46491 to g2d.GameState.
at Function/http://adobe.com/AS3/2006/builtin::call()

It seems like game or gameState wouldn’t be valid instances, but they definitely are. So I’m assuming it doesn’t somehow know what object the method to be tested belongs to and its throwing this error.

Any ideas?

  • 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-16T07:59:46+00:00Added an answer on May 16, 2026 at 7:59 am

    function.call requires a list of parameters, the same as if you were to call the function normally.

    If you want to pass an array of parameters, you should use function.apply instead.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping 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.