Error #1034 Type Coercion Failed Cannot Convert To Flash.display.displayobject
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up AS3: Error #1034: Type Coercion failed: cannot convert to flash.display.DisplayObject up vote 1 down vote favorite having some trouble with hitTestObject and now Flash is telling me it can't convert my ship to a display object.. my problem is the ship class extends Sprite to begin with so I don't know what's going on: Compile error shows this: TypeError: Error #1034: Type Coercion failed: cannot convert Ship$ to flash.display.DisplayObject. at Control/controlgame() Control / controlgame() is this: function controlgame(e:Event) { for (var i = 0; i < wprojectiles.length; i ++) { if (wprojectiles[i].x < -200 || wprojectiles[i].x > 750 || wprojectiles[i].y < -200 || wprojectiles[i].y > 600) { parent.removeChild(wprojectiles[i]); wprojectiles.splice(i,1); } if (wprojectiles[i].hitTestObject(Ship)) { parent.removeChild(wprojectiles[i]); wprojectiles.splice(i,1); } } } Using the debugger, I get this error: TypeError: Error #1034: Type Coercion failed: cannot convert Ship$ to flash.display.DisplayObject. at Control/controlgame()[C:\Users\Harry\Desktop\Flash Games\Games\Dodge\Control.as:29] Line 29, seen in the above snippet, is this: if (wprojectiles[i].hitTestObject(Ship)) { Tearing my hair out here, tried everything I could think of and I get this error every single time, no matter what I do! Help would be so badly appreciated! Thanks in advance. e: if it bears relevance, this is my document class file actionscript-3 share|improve this question edited Jan 26 '12 at 13:43 asked Jan 26 '12 at 13:26 hazdog 811319 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted Where did you declare Ship? It looks like you're using
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up http://stackoverflow.com/questions/9018756/as3-error-1034-type-coercion-failed-cannot-convert-to-flash-display-displayo AS3 Error #1034: Type Coercion failed: up vote 0 down vote favorite I have a problem with this class, it throws a 1034 error : Type Coercion failed: cannot convert Green$ to flash.display.DisplayObject. I believe it is linked to the bg variable. A little help would be greatly apreciated thanks public var bg1:Green; public var bg2:Red; public var bg3:Blue; public var bg:MovieClip; public http://stackoverflow.com/questions/19383742/as3-error-1034-type-coercion-failed var bgElements_arr : Array; public var bg_arr : Array; public function Level1(target:Stage) { bg1 = new Green; bg2 = new Red; bg3 = new Blue; bgElements_arr = new Array(Green, Red, Blue); bg_arr = new Array(); for(var bg_i:int =0; bg_i <5; bg_i++) { bg=bgElements_arr[Math.floor(Math.random() * bgElements_arr.length)]; bg_arr.push(bg); target.addChild(bg); } actionscript-3 flash types runtime-error share|improve this question asked Oct 15 '13 at 14:25 Yaniv 715 What's the Green's type? –Pan Oct 15 '13 at 14:34 It should be a movie clip. as it is a linkage to movie clip in the library –Yaniv Oct 15 '13 at 14:36 So try target.addChild(bg as DisplayObject) –Pan Oct 15 '13 at 14:37 I think I made a mistake in the bgElements_arr declaration, I declare types instaead of variables....I will dig this –Yaniv Oct 15 '13 at 14:38 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted You trying to add on stage Class constructor , not instance . Add 'new' keyword and it will work : for(var bg_i:int =0; bg_i <5; bg_i++) { bg= new bgElements_arr[Math.floor(Math.random() * bgElements_arr.leng
Winners & New Hub | #Inktober (AS3) Type Coercion failed http://www.newgrounds.com/bbs/topic/1120494 1,592 Views 8 Replies New Topic Respond to this Topic « Return to Game Development Forum Forum Index Stainez Stainez Member since: Nov. 8, 2009 Offline. Send Private Message Browse All Posts (4) Block Forum Stats Member Level 01 Blank Slate (AS3) Type error #1034 Coercion failed 2009-11-08 17:37:13 Reply Hi! I'm new to programming, and am trying to learn as I go along. I'm doing pretty good, except I've been stuck for a good while now. So before i go completely nuts, I thought I'd plea to the helpful error #1034 type ones and hope for the best. Many thanks in advance for your time. The "missile_hc" is created, but not moved. What exactly am I missing? I get this error:TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip$ to flash.display.DisplayObject. function spawn_horseshoeCrab():void{ var enemy_horseshoeCrab_var:MovieClip = new enemy_hc(); addChild(enemy_horseshoeCrab_var); enemy_horseshoeCrab_var.x = (Math.round (100 + Math.random() * 300)); enemy_horseshoeCrab_var.y = -10; enemy_horseshoeCrab_var.addEventListener(Event.ENTER_FRAME, enemy_horseshoeCrab_move); } function enemy_horseshoeCrab_move(a:Event):void{ a.target.y += 1; if(a.target.y >= 500){ a.target.removeEventListener(Event.ENTER_FRAME, enemy_horseshoeCrab_move) removeChild(MovieClip(a.target)); spawn_horseshoeCrab();} if((a.target.x + 20) >= shipvar.x && (a.target.x - 20) <= shipvar.x && (a.target.y + 20) <= shipvar.y){ var missile_hc:MovieClip = new enemy_hc_attack_1(); addChild(missile_hc); missile_hc.x = a.target.x - 7; missile_hc.y = a.target.y + 5; missile_hc.addEventListener(Event.ENTER_FRAME, weapon_hc1_move); //firesound.play(); } } function weapon_hc1_move(e:Event):void{ e.target.y += 2; if(e.target.y <= 550){ e.target.removeEventListener(Event.ENTER_FRAME, weapon_hc1_move) e.target.removeChild(MovieClip);} } PakaPaka PakaPaka Member since: Nov. 7, 2007 Offline. Send P