flash - Clear Class ( new ClassName() ) -
Question: What's behind the var animals: Pets = new pets (); ??
Script:
package {import flash.events.MouseEvent; PublicClick Pets {Public Function Pets () {// Constructor Code on my_btn.addEventListener (MouseEvent.CLICK, onClick)} onClick (e: MouseEvent) {trace (start); }}}
Problem: When I call pet classes with second class (new pet); , This class runs and addEventListener works fine but:
First time: trace result
start
second time: Trace Results
Start
Start
Third Time: Detecting Result
Start
Start
Assume
my_btn
is an example of a button on the forum, every time youpet Creates a new example of animals
So you are adding a newMouseEvent.CLICK
event handler to the samemy_btn
example.There are some different ways to decide this, but it depends on how you want to work. If you want a
my_btn
example to exist, thenMouseEvent.CLICK
is excluded from thePets
class (and only add it once) Add out If your own button is needed for eachpet
, then for a quick example ofmy_btn
for every example ofpet
institute (Currently it looks like you are referring to all thepet examples of
my_btn
).
Comments
Post a Comment