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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:30:03+00:00 2026-05-18T02:30:03+00:00

i have no idea why the following code doesn’t work. i’m simply passing and

  • 0

i have no idea why the following code doesn’t work.

i’m simply passing and then repassing Shape objects as a rest parameter. when the objects arrive at the final function, they trace as [object Shape], but then on the next line i receive a type coercion failure, stating it couldn’t be converted into a Shape.

output:

[object Shape],[object Shape]
TypeError: Error #1034: Type Coercion failed: cannot convert []@27b68921 to flash.display.Shape.
    at Test/receiver()
    at Test/passer()
    at Test()

code:

package
{   
import flash.display.Sprite;
import flash.display.Shape;

public class Test extends Sprite
    {
    public function Test()
        {
        //Create Shapes
        var myFirstShape:Shape = new Shape();
        myFirstShape.graphics.beginFill(0);
        myFirstShape.graphics.drawRoundRect(0, 0, 100, 100, 50);

        var mySecondShape:Shape = new Shape();
        mySecondShape.graphics.beginFill(0);
        mySecondShape.graphics.drawRoundRect(0, 0, 100, 100, 50);

        //Pass Shapes
        passer(myFirstShape, mySecondShape);
        }

    private function passer(...items):void
        {
        //Pass Shapes Again
        receiver(items);
        }

    private function receiver(...items):void
        {
        //Rest Trace As [object Shape], [object Shape]
        trace(items);

        //Type Coercion Failed ??!!
        for each    (var element:Shape in items)
                    {
                    trace(element);
                    }
        }
    }
}
  • 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-18T02:30:04+00:00Added an answer on May 18, 2026 at 2:30 am

    This is a bit counter intuitive at first sight, but it actually makes sense…

    When you declare a rest parameter, the arguments that you actually pass are wrapped in an Array at runtime.

    That means, if you do:

    myFunction(1,2,3);
    

    Your function will receive an Array with 3 values.

    This is exactly what’s going on here:

    private function passer(...items):void
        {
        //Pass Shapes Again
        receiver(items);
        }
    

    ìtems is itself an Array in the body of passer. But when you call receiver, this Array that contains 2 shapes is wrapped in another Array, because you declared that receiver took a rest parameter.

    When your loop in receiver tries to convert each item into a Shape, it fails (because you can’t convert an Array into a Shape).

    You could see this changing your code a bit:

    private function receiver(...items):void
        {
        //Rest Trace As [object Shape], [object Shape]
        trace(items);
        trace(items.length);// --> traces 1
        trace(items[0].length);// --> traces 2; this is the Array you want.
    
    }
    

    So, you have a couple of options to fix this, depending on what you really want to achieve.

    1) Have receiver “unwrap” the rest parameters to get the inner array. Basically loop thorough items[0] instead of items.

    2) Change you function signature to:

    private function receiver(items:Array):void
    

    3) Change the way you call receiver so the array is passed as a list of arguments:

        private function passer(...items):void
        {
        //Pass Shapes Again
        receiver.apply(this,items);
        }
    

    The effect of this would be equivalent to doing this:

    receiver(items[0],items[1]);
    

    Except it handles the list of items dynamically, of course.

    If you really need passer to take a rest parameter, you could go with option 3). Otherwise, I’d choose Option 2). Option 1) is the one I like the least, as it’s the most brittle, but it’s also a valid option.

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

Sidebar

Related Questions

I have no idea why this is happening. I have some very straightforward code,
I have the following code and it works correctly in FF and IE8 but
I have the following code which I stripped out of any non-essential lines to
I have the following code and it's working (as usual) in everything but IE.
The following code works fine in FF, but doesn't in IE7 - when clicking
I have the following code (generates a quadratic function given the a, b, and
For the following code, I can't get the string.Replace to work: someTestString.Replace(someID.ToString(), sessionID); when
I have the following declaration in my code: u32 volatile __attribute__((nocast)) *A, *B; Is
do you have idea, if there would be some nice way to browse/log JMS
I have this idea for a free backup application. The largest problem I need

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.