Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>You can't just reference to <code>enemy</code> without any further specification (it will assume enemy is a child of the movieclip in which you placed the code. Try <code>stage.enemy</code> instead, and <code>this</code>, or <code>this.parent</code> instead of <code>axe</code>. (Assuming enemy is a movieclip on the <code>stage</code>, and the code you posted is inside <code>axe</code>) Also, you should change <code>removeChild(enemy.stage)</code> to <code>stage.removeChild(stage.enemy)</code>, and you should probably look into variable scopes.</em></p> <hr> <p>Edit: Nope. Sorry for that, just pretend you didn't read that (Forgot you can't just reference objects through Stage)</p> <p>To be completely honest with you, this is the way I started as well but it's not the proper approach to flash coding. Firstly, you should try to keep all your code on the main timeline, and not in separate movieclips, in order for it to work together better. Once you get the hang of it, you should check out Object Oriented programming as well. It really increases the workflow and enables you to create bigger and way more complicated scripts.</p> <p>more edits:</p> <p>So to put this <strong>on the main timeline</strong>, would require something such as:</p> <pre><code>stage.addEventListener(Event.ENTER_FRAME, loop); function loop(event:Event):void { if (axe.hitTestObject(enemy)) { this.removeChild(enemy) } } </code></pre> <p>Which is cleaner and more readable (and easier to find) as well. (<strong>Assuming <code>axe</code> and <code>enemy</code> are movieclips on the main stage</strong>)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload