Skip to main content
December 13, 2012
Answered

Error #1034: Type Coercion failed

  • December 13, 2012
  • 1 reply
  • 3095 views

import flash.events.*;

import flash.display.*;

var origX:Number;

var origY:Number;

var target:DisplayObject;

var matchNum:uint;

redClick.buttonMode = true;

blueClick.buttonMode = true;

yellowClick.buttonMode = true;

redClick.addEventListener(MouseEvent.MOUSE_DOWN, redDrag);

function redDrag(event:MouseEvent):void

{

          redClick.origX = redClick.x;

          redClick.origY = redClick.y;

          blueClick.origX = blueClick.x;

          blueClick.origY = blueClick.y;

          yellowClick.origX = yellowClick.x;

          yellowClick.origY = yellowClick.y;

          stage.addEventListener(MouseEvent.MOUSE_UP, drop);

          redClick.startDrag();

          stage.addChild(this);

}

blueClick.addEventListener(MouseEvent.MOUSE_DOWN, blueDrag);

function blueDrag(event:MouseEvent):void

{

          redClick.origX = redClick.x;

          redClick.origY = redClick.y;

          blueClick.origX = blueClick.x;

          blueClick.origY = blueClick.y;

          yellowClick.origX = yellowClick.x;

          yellowClick.origY = yellowClick.y;

          stage.addEventListener(MouseEvent.MOUSE_UP, drop);

          blueClick.startDrag();

          stage.addChild(this);

}

yellowClick.addEventListener(MouseEvent.MOUSE_DOWN, yellowDrag);

function yellowDrag(event:MouseEvent):void

{

          redClick.origX = redClick.x;

          redClick.origY = redClick.y;

          blueClick.origX = blueClick.x;

          blueClick.origY = blueClick.y;

          yellowClick.origX = yellowClick.x;

          yellowClick.origY = yellowClick.y;

          stage.addEventListener(MouseEvent.MOUSE_UP, drop);

          yellowClick.startDrag();

          stage.addChild(this);

}

function drop(event:MouseEvent):void

{

          stage.removeEventListener(MouseEvent.MOUSE_UP, drop);

          stopDrag();

          if (redClick.hitTestObject(redDrop))

          {

                    redClick.visible = false;

                    redDrop.alpha = 1;

                    matchNum++;

          }

          if (blueClick.hitTestObject(blueDrop))

          {

                    blueClick.visible = false;

                    blueDrop.alpha = 1;

                    matchNum++;

          }

          if (yellowClick.hitTestObject(yellowDrop))

          {

                    yellowClick.visible = false;

                    yellowDrop.alpha = 1;

                    matchNum++;

          }

 

          redClick.x = redClick.origX;

          redClick.y = redClick.origY;

          blueClick.x = blueClick.origX;

          blueClick.y = blueClick.origY;

          yellowClick.x = yellowClick.origX;

          yellowClick.y = yellowClick.origY;

 

          if (matchNum > 2)

          {

                    MovieClip(parent).gotoAndStop(2);

          }

}

stop();

here is the error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@4c845089 to flash.display.MovieClip.

          at dragdrop_fla::Symbol1_1/drop()

Pls help~~~~>n<

This topic has been closed for replies.
Correct answer kglad

I recreated a portion of your design based on what you showed/described and am able to reproduce the error.  I guess I don't know enough to be able to understand why it happens.  I will see if I can get the attention of others that might have an idea.


the problem is caused by these statements:

stage.addChild(this);

change those to:

this.parent.addChild(this);  // or reparent "this" to the main timeline instead of the stage when you need to reference the main timeline.

p.s.  "this" will be visible throughout your main timeline unless you use removeChild.  ie, you might want:

if(matchNum>2){

this.parent.removeChild(this);

      MovieClip(this.parent).gotoAndStop(2);

}

1 reply

Ned Murphy
Legend
December 13, 2012

The only thing I can see where you are trying to coerce something into being a MovieClip is in the last line of the drop() function.  If all that code is in the main timeline, then just try using:  gotoAndStop(2);

December 13, 2012

Thanks for reply.

No, this code is not in the main timeline

Ned Murphy
Legend
December 13, 2012

Go into your Flash Publish Settings and select the option to Permit Debugging.  This can enhance the error message by including the number of the line where the troubled code can be found.