How come I can't convert the root variable to a MovieClip?
in 1 of custom classes program trying access main timeline within it. following code have used before, reason not seem working now. full error (during runtime, not during compiling)
[code]
typeerror: error #1034: type coercion failed: cannot convert flash.display::stage@28132041 flash.display.movieclip.
@ buttongame/onaddedtostage()
@ flash.display::displayobjectcontainer/addchild()
@ flash.display::stage/addchild()
@ recover_coingame_fla::maintimeline/frame2()
[/code]
and code is:
[code]
package {
import flash.display.movieclip;
import flash.events.event;
import flash.media.sound;
import flash.events.mouseevent;
public class buttongame extends movieclip
{ private var _root:object;
private var buttonsound1:sound;
public function buttongame(btnx:int, btny:int, btnwidth:int, btnheight:int, btnstring:string)
{
addeventlistener(mouseevent.click, clickhandler);
addeventlistener(event.added_to_stage, onaddedtostage);
}
function onaddedtostage(e:event):void
{
_root = movieclip(root); //code error referencing to.
buttonsound1 = _root._resource.coinsound;
removeeventlistener(event.added_to_stage, onaddedtostage);
}
private function clickhandler(e:mouseevent):void
{
buttonsound1.play();
}
}
}
[/code]
and same exact code worked in different class, reason doesn't seem work this.
please i've been stuck on hour, trying many different things , searching internet.
-thanks
use
private var _root:movieclip;
but casting object wouldn't cause error. fla must using other buttongame class file.
More discussions in ActionScript 3
adobe
Comments
Post a Comment