Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.23 / 5.00 3,881 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.93 / 5.00 4,634 ViewsSo instead of adding listeners to everything I came up with this way for example;
I create one mouse click event listener that check whether the object I click has a property "button"(the name doesn't matter) set to true and if it's true it executes a function property that comes with the object.
Is it good to use that kind of alternative or should I drop it?
stage.addEventListener(MouseEvent.CLICK, MouseHandler)
function MouseHandler(e:MouseEvent) {
if (e.target.button == true) {e.target.func()}
}
object.button = true
object.func = Exe
function Exe() { } I wonder what your motivation behind this question is.
Why don't you want to add the listener?
At 7/9/13 04:33 PM, NecroBlight wrote: stage.addEventListener(MouseEvent.CLICK, MouseHandler)
function MouseHandler(e:MouseEvent) {
if (e.target.button == true) {e.target.func()}
}
object.button = true
object.func = Exe
function Exe() { }
That's what classes are for.
Define the function and add the listener there.
At 7/9/13 04:46 PM, milchreis wrote: I wonder what your motivation behind this question is.
Why don't you want to add the listener?
At 7/9/13 04:33 PM, NecroBlight wrote: stage.addEventListener(MouseEvent.CLICK, MouseHandler)That's what classes are for.
function MouseHandler(e:MouseEvent) {
if (e.target.button == true) {e.target.func()}
}
object.button = true
object.func = Exe
function Exe() { }
Define the function and add the listener there.
But I really prefer to avoid managing listeners, adding and removing them always.
At 7/9/13 04:49 PM, NecroBlight wrote: But I really prefer to avoid managing listeners, adding and removing them always.
Well it's an integral part of AS3 and most programming languages. You can just add one listener and check which object with clicked with currentTarget, but that's the best you're probably going to get.
At 7/9/13 04:56 PM, MintPaw wrote:At 7/9/13 04:49 PM, NecroBlight wrote: But I really prefer to avoid managing listeners, adding and removing them always.Well it's an integral part of AS3 and most programming languages. You can just add one listener and check which object with clicked with currentTarget, but that's the best you're probably going to get.
I don't get what you mean, but what problem is there with my alternative?
At 7/9/13 04:49 PM, NecroBlight wrote: But I really prefer to avoid managing listeners, adding and removing them always.
So you'd rather manage flag variables and mechanisms to identify them.
What is this function doing that you want to execute upon that event?
At 7/9/13 06:00 PM, milchreis wrote:At 7/9/13 04:49 PM, NecroBlight wrote: But I really prefer to avoid managing listeners, adding and removing them always.So you'd rather manage flag variables and mechanisms to identify them.
What is this function doing that you want to execute upon that event?
I use it for many different function things, nothing specific. But it's very helpful for something like tooltip that isn't used only in one class but across many classes. Much easier than making a separate listener and function for every time. I just make one single class with a listener on stage and the mechanics for creating a tooltip instance and just put a flag for objects I want a tooltip for and properties needed for that function.
At 7/9/13 06:09 PM, NecroBlight wrote:
You'd handle the management of listeners once in the tooltip class.
You sound like that's an aweful lot of work to do.
There is no nice way to put it but this is seriously a terrible idea. Don't do this.
At 7/9/13 05:04 PM, NecroBlight wrote: I don't get what you mean, but what problem is there with my alternative?
- It's slow/less efficient.
- It doesn't make any sense.
- It's not extensible.
- It's more work to manage.
- It's more error prone.
- It's not the way that the language was designed to be used.
- It will confuse the hell out of anyone who reads your code.
At 7/9/13 06:09 PM, NecroBlight wrote: I just make one single class with a listener on stage and the mechanics for creating a tooltip instance and just put a flag for objects I want a tooltip for and properties needed for that function.
Write a function in your tooltip class to add the necessary listener to the appropriate object.
public class Tooltip {
public function listen(object:EventDispatcher, callback:Function):void {
object.addEventListener(MouseEvent.CLICK, callback);
}
}
What is difficult about that?
At 7/9/13 07:48 PM, Diki wrote:
public class Tooltip {
public function listen(object:EventDispatcher, callback:Function):void {
object.addEventListener(MouseEvent.CLICK, callback);
}
}
What is difficult about that?
And then I need remove those listeners each and every time.
At 7/10/13 04:32 AM, NecroBlight wrote: And then I need remove those listeners each and every time.
You can make the listener weak.
At 7/10/13 07:33 AM, milchreis wrote:At 7/10/13 04:32 AM, NecroBlight wrote: And then I need remove those listeners each and every time.You can make the listener weak.
But how I understood it, weak referencing doesn't completely remove the listener, if I'm wrong please correct me.
At 7/10/13 11:39 AM, NecroBlight wrote:At 7/10/13 07:33 AM, milchreis wrote:But how I understood it, weak referencing doesn't completely remove the listener, if I'm wrong please correct me.At 7/10/13 04:32 AM, NecroBlight wrote: And then I need remove those listeners each and every time.You can make the listener weak.
The reason you'd want to remove listeners is so they can be removed from memory, if the listeners are connected then the objects they're connected to wont leave memory because they are still "in-use", weak references will not hold objects in memory like that.
At 7/10/13 11:39 AM, NecroBlight wrote:At 7/10/13 07:33 AM, milchreis wrote:But how I understood it, weak referencing doesn't completely remove the listener, if I'm wrong please correct me.At 7/10/13 04:32 AM, NecroBlight wrote: And then I need remove those listeners each and every time.You can make the listener weak.
So you complain that you have to remove listeners, after a solution is presented to you, you complain that you don't remove them. lol
Stop trolling please.
At 7/10/13 11:39 AM, NecroBlight wrote: But how I understood it, weak referencing doesn't completely remove the listener, if I'm wrong please correct me.
You're wrong. Do you think it only removes half of the listener or something?
At 7/10/13 01:41 PM, MintPaw wrote:
The reason you'd want to remove listeners is so they can be removed from memory, if the listeners are connected then the objects they're connected to wont leave memory because they are still "in-use", weak references will not hold objects in memory like that.
I see, thanks for explaining.
At 7/10/13 03:49 PM, milchreis wrote:
So you complain that you have to remove listeners, after a solution is presented to you, you complain that you don't remove them. lol
Stop trolling please.
What is wrong with you? :/
At 7/10/13 07:25 PM, Diki wrote:At 7/10/13 11:39 AM, NecroBlight wrote: But how I understood it, weak referencing doesn't completely remove the listener, if I'm wrong please correct me.You're wrong. Do you think it only removes half of the listener or something?
No, I just thought it would still leave some kind of data remnants or something.
At 7/20/13 08:54 AM, NecroBlight wrote: What is wrong with you? :/
Nothing, I just pointed out that you have opposing goals.
At 7/20/13 09:37 AM, milchreis wrote:At 7/20/13 08:54 AM, NecroBlight wrote: What is wrong with you? :/Nothing, I just pointed out that you have opposing goals.
Then you probably didn't understand me correctly, my goal was to not need to manually remove listeners each and every time, and in the comment you replied to I said that I thought that weak referencing doesn't completely remove the listener
And the "What is wrong with you?" was primarily directed at the "Don't troll please" comment which was absolutely unnecessary.
At 7/20/13 11:00 AM, NecroBlight wrote:At 7/20/13 09:37 AM, milchreis wrote:Then you probably didn't understand me correctly, my goal was to not need to manually remove listeners each and every time, and in the comment you replied to I said that I thought that weak referencing doesn't completely remove the listenerAt 7/20/13 08:54 AM, NecroBlight wrote: What is wrong with you? :/Nothing, I just pointed out that you have opposing goals.
And the "What is wrong with you?" was primarily directed at the "Don't troll please" comment which was absolutely unnecessary.
You really don't seem to know exactly what you want to do here. You have to remove event listeners every time, you can try to automate the process with some kind of janitor class (look up janitor.as), or you can use weak listeners and forget about removing them, which may be what you want?
It seems like you want to have to remove an event listener, just not to remove multiple? And even if you do set it up so you can remove them all in one line you'll still have to do it "every time" as in every time the class is created, you're saying completely contradicting things and it's reasonable to assume that you're not being serious with everything you're saying.
At 7/20/13 03:37 PM, MintPaw wrote:
You really don't seem to know exactly what you want to do here. You have to remove event listeners every time, you can try to automate the process with some kind of janitor class (look up janitor.as), or you can use weak listeners and forget about removing them, which may be what you want?
It seems like you want to have to remove an event listener, just not to remove multiple? And even if you do set it up so you can remove them all in one line you'll still have to do it "every time" as in every time the class is created, you're saying completely contradicting things and it's reasonable to assume that you're not being serious with everything you're saying.
What? what are you talking about? all along I said that I don't want to be forced to manually remove listeners, I wanted to do it like you said in the first paragraph, an automate way to do it.
At 7/21/13 05:26 PM, NecroBlight wrote: What? what are you talking about? all along I said that I don't want to be forced to manually remove listeners, I wanted to do it like you said in the first paragraph, an automate way to do it.
And it was explained to you (more than once) that you can use weak listeners so that they will be automatically removed. Then you said this:
At 7/21/13 05:26 PM, NecroBlight wrote: But how I understood it, weak referencing doesn't completely remove the listener, if I'm wrong please correct me.
And you were wrong, and were corrected, yet you keep asking how to automatically remove listeners.
This is why we don't think that you're posting in earnest.
I think that you dont have to have more then 1 listener of same type in all of code, if you do that way you dont even have to remove them...
RangeError: Error #1125: The index 4 is out of range 4.
At 7/21/13 05:54 PM, Diki wrote:At 7/21/13 05:26 PM, NecroBlight wrote:And it was explained to you (more than once) that you can use weak listeners so that they will be automatically removed. Then you said this:
At 7/21/13 05:26 PM, NecroBlight wrote:And you were wrong, and were corrected, yet you keep asking how to automatically remove listeners.
This is why we don't think that you're posting in earnest.
Wait, at which point was I kept asking about it again after I've been corrected? the only thing I did was just explain the situation to the one who called me a troll (that I came looking for a way to get reed of a way to manually remove listeners and didn't ask for any conflicting questions). . . :|
This is beyond irritating.
At 7/21/13 05:54 PM, Diki wrote: And it was explained to you (more than once) that you can use weak listeners so that they will be automatically removed. Then you said this:
More than once? I replied to the first person who mentioned it. And didn't even argue about, just inquired about my misunderstanding of weak refrencing.
Really, I think I better avoid asking anything here in the future from now on if I get such reaction for simply seeking help. :/
NecroBlight obviously did not know exactly that having a weak listener meant it would get removed when the object was destroyed. Which is what he was trying to do in the first place. When told he could make the listener weak, he even very clearly expressed that he needed clarification that weak listeners indeed worked like that, and implied that he did look them up, but had misunderstood them, hence the need for asking for clarification.
And that's when milchreis jumped to calling him a troll.
I think MintPaw explained what NecroBlight needed in his first post.
His question was answered and he thanked you for your answers, he didn't "keep asking" the same question, he was posting in reply to the other posts.
I think if we all gave each other the benefit of doubt the forum would be a lot more welcoming to people.