Copy link to clipboard
Copied
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<
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); |
}
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Thanks for reply.
No, this code is not in the main timeline
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@2e185089 to flash.display.MovieClip.
at dragdrop_fla::Symbol1_1/drop()[dragdrop_fla.Symbol1_1::frame1:95]
which is
MovieClip(parent).gotoAndStop(2);
Copy link to clipboard
Copied
Try changing that to be: MovieClip(root).gotoAndStop(2);
Copy link to clipboard
Copied
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@4a29a089 to flash.display.MovieClip.
at dragdrop_fla::Symbol1_1/drop()[dragdrop_fla.Symbol1_1::frame1:95]
not working, same error
Copy link to clipboard
Copied
Describe the scenario for this code. Where is it?
Copy link to clipboard
Copied
As you can see , this is the main timeline, that code is inside a movieClip which is at frame 1.
If you want to ask, why not put all the thing on the main timeline? This is because, I do another game which have the same problem like this, I testing and put the code that have problem in different places and testing where have the problem, I found that if I delete all the drag and drop code, it can function well . Then I create a button which can link to parent page, it can function well also ,but if I start to drag something then the function is not work.
I wonder that is it the drag and drop code got problem? then I open a new as3 and put in similar code to continue testing.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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); |
}
Copy link to clipboard
Copied
Good eye... I missed the addChild lines (bad eye - me).
Copy link to clipboard
Copied
Thanks for reply.It come out with another error which is,
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at dragdrop_fla::Symbol1_1/drop()[dragdrop_fla.Symbol1_1::frame1:96]
and line 96 is,
MovieClip(this.parent).gotoAndStop(2);
Copy link to clipboard
Copied
again, change all your:
stage.addChild(this);
to:
this.parent.addChild(this);
Copy link to clipboard
Copied
Changed. But same
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at dragdrop_fla::Symbol1_1/drop()[dragdrop_fla.Symbol1_1::frame1:96]
and line 96 is,
MovieClip(this.parent).gotoAndStop(2);
Copy link to clipboard
Copied
Oops, I am sorry about that, its my false>n<
If I dont add this.parent.removeChild(this);, it work perfectly .
Thank you very much~
Copy link to clipboard
Copied
you're welcome.
p.s. this.parent.removeChild(this) should appear after your MovieClip(this.parent).gotoAndStop(2) statement, if you use it.