• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ActionScript 3.0: Error #1034: Type Coercion failed: cannot convert displayObject$ to DefaultPackage

New Here ,
Dec 20, 2013 Dec 20, 2013

Copy link to clipboard

Copied

I'm a student I have a final project want to deliver it after two days.

I'm making a drag and drop game, I watched a tutorial to do that.

But after ending coding I faced a weird error!

I've I checked that my code is the same as the code in the tutorial.

_________________________________

This is the Debug error report:

    Attempting to launch and connect to Player using URL E:\FL\ActionScript\Drag and Drop Project\DragAndDrop.swf

    [SWF] E:\FL\ActionScript\Drag and Drop Project\DragAndDrop.swf - 87403 bytes after decompression

    TypeError: Error #1034: Type Coercion failed: cannot convert paper1$ to DragDrop.

              at Targets()

_________________________________

My `.fla` File is containing 12 Objects to drag and another 12 Objects to drop on it.

The idea here is when drop the Object on the target the Object will become invisible and the target become visible (in `.fla` file `target alpha = 0`).

I made two classes:

DragDrop.as : for the objects that I'm going to drag.

Targets.as  : for the targets that I'm going to drop Objects on it.

Note: match function is to animate "GameOver" MovieClip When complete the game.

DragDrop.as:

    package

    {

              import flash.display.*;

              import flash.events.*;

   

              public class DragDrop extends Sprite

              {

                        var origX:Number;

                        var origY:Number;

                        var target:DisplayObject;

   

                        public function DragDrop()

                        {

                                  // constructor code

                                  origX = x;

                                  origY = y;

                                  addEventListener(MouseEvent.MOUSE_DOWN, drag);

                                  buttonMode = true;

                        }

   

                        function drag(evt:MouseEvent):void

                        {

                                  stage.addEventListener(MouseEvent.MOUSE_UP, drop);

                                  startDrag();

                                  parent.addChild(this);

                        }

   

                        function drop(evt:MouseEvent):void

                        {

                                  stage.removeEventListener(MouseEvent.MOUSE_UP, drop);

                                  stopDrag();

   

                                  if(hitTestObject(target))

                                  {

                                            visible = false;

                                            target.alpha = 1;

                                            Object(parent).match();

                                  }

   

                                  x = origX;

                                  y = origY;

                        }

   

              }

   

    }

Targets.as:

    package

    {

   

              import flash.display.*;

              import flash.events.*;

   

   

              public class Targets extends MovieClip

              {

                        var dragdrops:Array;

                        var numOfMatches:uint = 0;

                        var speed:Number = 25;

   

                        public function Targets()

                        {

                                  // constructor code

                                  dragdrops = [paper1,paper2,paper3,paper4,paper5,paper6,

                                                                 paper7,paper8,paper9,paper10,paper11,paper12,];

                                                                

                                  var currentObject:DragDrop;

                                  for(var i:uint = 0; i < dragdrops.length; i++)

                                  {

                                            currentObject = dragdrops;

                                            currentObject.target = getChildByName(currentObject.name + "_target");

                                  }

                        }

   

                        public function match():void

                        {

                                  numOfMatches++;

                                  if(numOfMatches == dragdrops.length)

                                  {

                                            win.addEventListener(Event.ENTER_FRAME, winGame);

                                  }

                        }

   

                        function winGame(event:Event):void

                        {

                                  win.y -= speed;

   

                                  if(win.y <= 0)

                                  {

                                            win.y = 0;

                                            win.removeEventListener(Event.ENTER_FRAME, winGame);

                                            win.addEventListener(MouseEvent.CLICK, clickWin);

                                  }

                        }

   

                        function clickWin(event:MouseEvent):void

                        {

                                  win.removeEventListener(MouseEvent.CLICK, clickWin);

                                  win.addEventListener(Event.ENTER_FRAME, animateDown);

   

                                  var currentObject:DragDrop;

                                  for(var i:uint = 0; i < dragdrops.length; i++)

                                  {

                                            currentObject = dragdrops;

                                            getChildByName(currentObject.name + "_target").alpha = 0;

                                            currentObject.visible = true;

                                  }

                                  numOfMatches = 0;

                                  addChild(win);

                        }

   

                        function animateDown(event:Event):void

                        {

                                  win.y += speed;

   

                                  if(win.y >= stage.stageHeight)

                                  {

                                            win.y = stage.stageHeight;

                                            win.removeEventListener(Event.ENTER_FRAME, animateDown);

                                  }

                        }

              }

   

    }

_________________________________

...Thanks

TOPICS
ActionScript

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2013 Dec 20, 2013

Copy link to clipboard

Copied

that error is telling you dragdrops (for at least one i) isn't a DragDrop object.

from what you posted it's not clear what your dragdrops elements are nor how Targets is obtaining those references.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2013 Dec 22, 2013

Copy link to clipboard

Copied

Thank you very much for replying.

- dragdrops represents: the dragable objects.

- Targets obtaining the dropable objects by hitTestObject, then the dropable objects visible is turned to false, & the target visible turned to true.

Dragable objects is a 12 elements all of them have an instance names: paper1....paper12.

When I focused to the project I noticed that I forget to give the dragable objects an instance names!

after making the instance names to them, a new error occures:

E:\FL\ActionScript\Drag and Drop Project\Targets.as, Line 111046: Type was not found or was not a compile-time constant: paper1.

This error is continuing to paper2, paper3.....paper12 !

Please download my project, I must deliver it to my college in 24/12. I will never forget your favor. thanks.

https://www.dropbox.com/s/8mdg5w17vvryzso/Drag%20and%20Drop%20Project.rar | 715KB

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2013 Dec 22, 2013

Copy link to clipboard

Copied

i only download and correct files if i'm hired.  free help i only offer via the adobe forums.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2013 Dec 22, 2013

Copy link to clipboard

Copied

aha, I got the point, sorry

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 24, 2013 Dec 24, 2013

Copy link to clipboard

Copied

no problem.

if you need more help, ask (questions that can be answered in a forum).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 24, 2013 Dec 24, 2013

Copy link to clipboard

Copied

LATEST

I solved the problem.

What did I did ?

* the Dragable objects is a bitmap objects I converted them to MC.....etc .

these bitmaps... I make them Break Apart  & then convert them to MC & give them the same instance names, and it works 100% fine

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines