Hey Everyone,
I have a question about some beginner as3 code. I’ve been using as2 for a long time and I make and teach basic games in flash with as2. Anyway, one of my clients is wanting to explore using flash for iOS development and I know that means finally moving over to as3. So anyway, I’m trying to just do the very basics of the first game i teach in as2, but in as3. I finally finally got most of it working, but it was immensely more complicated than as2, and I’ve still got some problems going on. It’s giving me a repeating compiler error that I suppose has something to do with referencing a an invisible movie clip I’m using for a hittest that doesn’t exist until a click. Anyway, I’ll attach the file and maybe someone can help me clean up my code? I’d really appreciate it.
Basically, mouse controls the circle, when you click, it changes colors, which would usually be an “attack”. If you click correctly on the square “enemy”, it turns pink showing that it’s been successfully “hit”. All of that works, but the errors are annoying and I’m sure I could be cleaner. Any help? It was so much less complicated in as2.
THANKS!
import flash.events.MouseEvent;
import flash.events.Event;
character.startDrag(true);
Mouse.hide();
this.addEventListener(MouseEvent.MOUSE_DOWN, hitcheck);
function hitcheck(event:Event):void{
if(character.hitTestObject(fakebutton)){
character.gotoAndPlay(2);
}
}
this.addEventListener(Event.ENTER_FRAME, hitcheck2);
function hitcheck2(event:Event):void{
if(character.hit.hitTestObject(enemy.enemy.hit)){
enemy.enemy.gotoAndPlay(2);
}
}