Hi EveryBody!
I see signals and find strange situation:
...
public var clicked:NativeSignal;
public function ButtonSound(_view:MovieClip)
{
view = _view;
init();
}
private function init():void
{
clicked = new NativeSignal(view, MouseEvent.CLICK, MouseEvent);
clicked.add(changeState);
clicked = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent);
clicked.add(overHandler);
clicked = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent);
clicked.add(outHandler);
...
And its work!
My button duspatch all 3 state.
trace(clicked.numListeners)// output:"1"
This means the signal keeps copies of all assigned without the
possibility of their removal?
The NativeSignal wraps addEventListener, so the changeState, overHandler, outHandler get passed to the native method. So when the view clicked all three methods would be called (this is expected). Ideally the gc would collect this when the view is removed and the class (which the native signals are in) is gc'd, but when this might happen is a guess.
My solution would be to use different variables for the the NativeSignals (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent the leak, but if this situation does occur then you could just use the view.removeEventListener(MouseEvent.CLICK, changeState), but then you have to rely on gc for the original signals being cleared.
But from what I'm seeing, I think you're trying to do the following:
public const signals : Vector.<NativeSignal> = new Vector.<NativeSignal>(3, true);
signals[0] = new NativeSignal(view, MouseEvent.CLICK, MouseEvent); signals[0].add(changeState); signals[1] = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent); signals[1].add(overHandler); signals[2] = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent); signals[2].add(outHandler);
If this is the aim, I would suggest making a immutable class that has 3 getters for each NativeSignal and having a method on it to determine how many signals are used in total. (get numListeners())
(other options exist as well, this is just how I would do it.)
> Hi EveryBody! > I see signals and find strange situation:
> ... > public var clicked:NativeSignal;
> public function ButtonSound(_view:MovieClip) > { > view = _view; > init(); > }
> private function init():void > {
> clicked = new NativeSignal(view, MouseEvent.CLICK, MouseEvent); > clicked.add(changeState); > clicked = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent); > clicked.add(overHandler); > clicked = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent); > clicked.add(outHandler); > ...
> And its work! > My button duspatch all 3 state. > trace(clicked.numListeners)// output:"1" > This means the signal keeps copies of all assigned without the > possibility of their removal?
> The NativeSignal wraps addEventListener, so the changeState, overHandler, > outHandler get passed to the native method. So when the view clicked all > three methods would be called (this is expected). Ideally the gc would > collect this when the view is removed and the class (which the native > signals are in) is gc'd, but when this might happen is a guess.
> My solution would be to use different variables for the the NativeSignals > (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent > the leak, but if this situation does occur then you could just use the > view.removeEventListener(MouseEvent.CLICK, changeState), but then you have > to rely on gc for the original signals being cleared.
> But from what I'm seeing, I think you're trying to do the following:
> public const signals : Vector.<NativeSignal> = new Vector.<NativeSignal>(3, > true);
> signals[0] = new NativeSignal(view, MouseEvent.CLICK, MouseEvent); > signals[0].add(changeState); > signals[1] = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent); > signals[1].add(overHandler); > signals[2] = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent); > signals[2].add(outHandler);
> If this is the aim, I would suggest making a immutable class that has 3 > getters for each NativeSignal and having a method on it to determine how > many signals are used in total. (get numListeners())
> (other options exist as well, this is just how I would do it.)
> Cheers > si
> On 24 Oct 2011, at 14:04, Leezarius wrote:
> > Hi EveryBody! > > I see signals and find strange situation:
> > ... > > public var clicked:NativeSignal;
> > public function ButtonSound(_view:MovieClip) > > { > > view = _view; > > init(); > > }
> > And its work! > > My button duspatch all 3 state. > > trace(clicked.numListeners)// output:"1" > > This means the signal keeps copies of all assigned without the > > possibility of their removal?
public var clicked:NativeSignal;
public var overed:NativeSignal;
public var outed:NativeSignal;
But I was wrong when copying and did not change signal names when
initializing.
I understand that the signal is a wrapper, but I think it's a bad
situation.
In the following case, for example, I have only one array
var customArray:Array;
customArray=[1,1,1];
customArray=[2,2,2];
customArray=[3,3,3];
And this array is [3,3,3]
In the case of a signal I can add any number of events and a problem
with garbage collector or uncontrolled behavior of the object.
Thanks.
On Oct 24, 7:03 pm, Simon Richardson <stickup...@gmail.com> wrote:
> The NativeSignal wraps addEventListener, so the changeState, overHandler, outHandler get passed to the native method. So when the view clicked all three methods would be called (this is expected). Ideally the gc would collect this when the view is removed and the class (which the native signals are in) is gc'd, but when this might happen is a guess.
> My solution would be to use different variables for the the NativeSignals (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent the leak, but if this situation does occur then you could just use the view.removeEventListener(MouseEvent.CLICK, changeState), but then you have to rely on gc for the original signals being cleared.
> But from what I'm seeing, I think you're trying to do the following:
> public const signals : Vector.<NativeSignal> = new Vector.<NativeSignal>(3, true);
> signals[0] = new NativeSignal(view, MouseEvent.CLICK, MouseEvent);
> signals[0].add(changeState);
> signals[1] = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent);
> signals[1].add(overHandler);
> signals[2] = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent);
> signals[2].add(outHandler);
> If this is the aim, I would suggest making a immutable class that has 3 getters for each NativeSignal and having a method on it to determine how many signals are used in total. (get numListeners())
> (other options exist as well, this is just how I would do it.)
> Cheers
> si
> On 24 Oct 2011, at 14:04, Leezarius wrote:
> > Hi EveryBody!
> > I see signals and find strange situation:
> > ...
> > public var clicked:NativeSignal;
> > public function ButtonSound(_view:MovieClip)
> > {
> > view = _view;
> > init();
> > }
> > And its work!
> > My button duspatch all 3 state.
> > trace(clicked.numListeners)// output:"1"
> > This means the signal keeps copies of all assigned without the
> > possibility of their removal?
> On Mon, Oct 24, 2011 at 8:03 AM, Simon Richardson <stickup...@gmail.com>wrote:
> > The NativeSignal wraps addEventListener, so the changeState, overHandler,
> > outHandler get passed to the native method. So when the view clicked all
> > three methods would be called (this is expected). Ideally the gc would
> > collect this when the view is removed and the class (which the native
> > signals are in) is gc'd, but when this might happen is a guess.
> > My solution would be to use different variables for the the NativeSignals
> > (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent
> > the leak, but if this situation does occur then you could just use the
> > view.removeEventListener(MouseEvent.CLICK, changeState), but then you have
> > to rely on gc for the original signals being cleared.
> > But from what I'm seeing, I think you're trying to do the following:
> > public const signals : Vector.<NativeSignal> = new Vector.<NativeSignal>(3,
> > true);
> > If this is the aim, I would suggest making a immutable class that has 3
> > getters for each NativeSignal and having a method on it to determine how
> > many signals are used in total. (get numListeners())
> > (other options exist as well, this is just how I would do it.)
> > Cheers
> > si
> > On 24 Oct 2011, at 14:04, Leezarius wrote:
> > > Hi EveryBody!
> > > I see signals and find strange situation:
> > > And its work!
> > > My button duspatch all 3 state.
> > > trace(clicked.numListeners)// output:"1"
> > > This means the signal keeps copies of all assigned without the
> > > possibility of their removal?
> public var clicked:NativeSignal; > public var overed:NativeSignal; > public var outed:NativeSignal;
> But I was wrong when copying and did not change signal names when > initializing. > I understand that the signal is a wrapper, but I think it's a bad > situation. > In the following case, for example, I have only one array > var customArray:Array; > customArray=[1,1,1]; > customArray=[2,2,2]; > customArray=[3,3,3]; > And this array is [3,3,3]
> In the case of a signal I can add any number of events and a problem > with garbage collector or uncontrolled behavior of the object. > Thanks.
> On Oct 24, 7:03 pm, Simon Richardson <stickup...@gmail.com> wrote: >> The NativeSignal wraps addEventListener, so the changeState, overHandler, outHandler get passed to the native method. So when the view clicked all three methods would be called (this is expected). Ideally the gc would collect this when the view is removed and the class (which the native signals are in) is gc'd, but when this might happen is a guess.
>> My solution would be to use different variables for the the NativeSignals (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent the leak, but if this situation does occur then you could just use the view.removeEventListener(MouseEvent.CLICK, changeState), but then you have to rely on gc for the original signals being cleared.
>> But from what I'm seeing, I think you're trying to do the following:
>> public const signals : Vector.<NativeSignal> = new Vector.<NativeSignal>(3, true);
>> signals[0] = new NativeSignal(view, MouseEvent.CLICK, MouseEvent); >> signals[0].add(changeState); >> signals[1] = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent); >> signals[1].add(overHandler); >> signals[2] = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent); >> signals[2].add(outHandler);
>> If this is the aim, I would suggest making a immutable class that has 3 getters for each NativeSignal and having a method on it to determine how many signals are used in total. (get numListeners())
>> (other options exist as well, this is just how I would do it.)
>> Cheers >> si
>> On 24 Oct 2011, at 14:04, Leezarius wrote:
>>> Hi EveryBody! >>> I see signals and find strange situation:
>>> ... >>> public var clicked:NativeSignal;
>>> public function ButtonSound(_view:MovieClip) >>> { >>> view = _view; >>> init(); >>> }
>>> private function init():void >>> {
>>> clicked = new NativeSignal(view, MouseEvent.CLICK, MouseEvent); >>> clicked.add(changeState); >>> clicked = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent); >>> clicked.add(overHandler); >>> clicked = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent); >>> clicked.add(outHandler); >>> ...
>>> And its work! >>> My button duspatch all 3 state. >>> trace(clicked.numListeners)// output:"1" >>> This means the signal keeps copies of all assigned without the >>> possibility of their removal?
That's the thing with listeners: the event source has a reference to them. It can't tell when you've nulled or replaced one of the references to the listening object. You need to clean up afterwards and this applies beyond Signals. At least removeAll() makes it easy.
On Mon, Oct 24, 2011 at 8:47 AM, Leezarius <leep...@gmail.com> wrote: > Simon Thanks! > I used three different signal
> public var clicked:NativeSignal; > public var overed:NativeSignal; > public var outed:NativeSignal;
> But I was wrong when copying and did not change signal names when > initializing. > I understand that the signal is a wrapper, but I think it's a bad > situation. > In the following case, for example, I have only one array > var customArray:Array; > customArray=[1,1,1]; > customArray=[2,2,2]; > customArray=[3,3,3]; > And this array is [3,3,3]
> In the case of a signal I can add any number of events and a problem > with garbage collector or uncontrolled behavior of the object. > Thanks.
> On Oct 24, 7:03 pm, Simon Richardson <stickup...@gmail.com> wrote: > > The NativeSignal wraps addEventListener, so the changeState, overHandler, > outHandler get passed to the native method. So when the view clicked all > three methods would be called (this is expected). Ideally the gc would > collect this when the view is removed and the class (which the native > signals are in) is gc'd, but when this might happen is a guess.
> > My solution would be to use different variables for the the NativeSignals > (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent > the leak, but if this situation does occur then you could just use the > view.removeEventListener(MouseEvent.CLICK, changeState), but then you have > to rely on gc for the original signals being cleared.
> > But from what I'm seeing, I think you're trying to do the following:
> > public const signals : Vector.<NativeSignal> = new > Vector.<NativeSignal>(3, true);
> > If this is the aim, I would suggest making a immutable class that has 3 > getters for each NativeSignal and having a method on it to determine how > many signals are used in total. (get numListeners())
> > (other options exist as well, this is just how I would do it.)
> > Cheers > > si
> > On 24 Oct 2011, at 14:04, Leezarius wrote:
> > > Hi EveryBody! > > > I see signals and find strange situation:
> > > And its work! > > > My button duspatch all 3 state. > > > trace(clicked.numListeners)// output:"1" > > > This means the signal keeps copies of all assigned without the > > > possibility of their removal?
> Which would behave in just the same way as the Signals do...
> Stray
> On 24 Oct 2011, at 16:47, Leezarius wrote:
> > Simon Thanks!
> > I used three different signal
> > public var clicked:NativeSignal;
> > public var overed:NativeSignal;
> > public var outed:NativeSignal;
> > But I was wrong when copying and did not change signal names when
> > initializing.
> > I understand that the signal is a wrapper, but I think it's a bad
> > situation.
> > In the following case, for example, I have only one array
> > var customArray:Array;
> > customArray=[1,1,1];
> > customArray=[2,2,2];
> > customArray=[3,3,3];
> > And this array is [3,3,3]
> > In the case of a signal I can add any number of events and a problem
> > with garbage collector or uncontrolled behavior of the object.
> > Thanks.
> > On Oct 24, 7:03 pm, Simon Richardson <stickup...@gmail.com> wrote:
> >> The NativeSignal wraps addEventListener, so the changeState, overHandler, outHandler get passed to the native method. So when the view clicked all three methods would be called (this is expected). Ideally the gc would collect this when the view is removed and the class (which the native signals are in) is gc'd, but when this might happen is a guess.
> >> My solution would be to use different variables for the the NativeSignals (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent the leak, but if this situation does occur then you could just use the view.removeEventListener(MouseEvent.CLICK, changeState), but then you have to rely on gc for the original signals being cleared.
> >> But from what I'm seeing, I think you're trying to do the following:
> >> public const signals : Vector.<NativeSignal> = new Vector.<NativeSignal>(3, true);
> >> If this is the aim, I would suggest making a immutable class that has 3 getters for each NativeSignal and having a method on it to determine how many signals are used in total. (get numListeners())
> >> (other options exist as well, this is just how I would do it.)
> >> Cheers
> >> si
> >> On 24 Oct 2011, at 14:04, Leezarius wrote:
> >>> Hi EveryBody!
> >>> I see signals and find strange situation:
> >>> ...
> >>> public var clicked:NativeSignal;
> >>> public function ButtonSound(_view:MovieClip)
> >>> {
> >>> view = _view;
> >>> init();
> >>> }
> >>> And its work!
> >>> My button duspatch all 3 state.
> >>> trace(clicked.numListeners)// output:"1"
> >>> This means the signal keeps copies of all assigned without the
> >>> possibility of their removal?
> That's the thing with listeners: the event source has a reference to them.
> It can't tell when you've nulled or replaced one of the references to the
> listening object. You need to clean up afterwards and this applies beyond
> Signals. At least removeAll() makes it easy.
> Robert
> On Mon, Oct 24, 2011 at 8:47 AM, Leezarius <leep...@gmail.com> wrote:
> > Simon Thanks!
> > I used three different signal
> > public var clicked:NativeSignal;
> > public var overed:NativeSignal;
> > public var outed:NativeSignal;
> > But I was wrong when copying and did not change signal names when
> > initializing.
> > I understand that the signal is a wrapper, but I think it's a bad
> > situation.
> > In the following case, for example, I have only one array
> > var customArray:Array;
> > customArray=[1,1,1];
> > customArray=[2,2,2];
> > customArray=[3,3,3];
> > And this array is [3,3,3]
> > In the case of a signal I can add any number of events and a problem
> > with garbage collector or uncontrolled behavior of the object.
> > Thanks.
> > On Oct 24, 7:03 pm, Simon Richardson <stickup...@gmail.com> wrote:
> > > The NativeSignal wraps addEventListener, so the changeState, overHandler,
> > outHandler get passed to the native method. So when the view clicked all
> > three methods would be called (this is expected). Ideally the gc would
> > collect this when the view is removed and the class (which the native
> > signals are in) is gc'd, but when this might happen is a guess.
> > > My solution would be to use different variables for the the NativeSignals
> > (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent
> > the leak, but if this situation does occur then you could just use the
> > view.removeEventListener(MouseEvent.CLICK, changeState), but then you have
> > to rely on gc for the original signals being cleared.
> > > But from what I'm seeing, I think you're trying to do the following:
> > > public const signals : Vector.<NativeSignal> = new
> > Vector.<NativeSignal>(3, true);
> > > If this is the aim, I would suggest making a immutable class that has 3
> > getters for each NativeSignal and having a method on it to determine how
> > many signals are used in total. (get numListeners())
> > > (other options exist as well, this is just how I would do it.)
> > > Cheers
> > > si
> > > On 24 Oct 2011, at 14:04, Leezarius wrote:
> > > > Hi EveryBody!
> > > > I see signals and find strange situation:
> > > > ...
> > > > public var clicked:NativeSignal;
> > > > And its work!
> > > > My button duspatch all 3 state.
> > > > trace(clicked.numListeners)// output:"1"
> > > > This means the signal keeps copies of all assigned without the
> > > > possibility of their removal?
>> Which would behave in just the same way as the Signals do...
>> Stray
>> On 24 Oct 2011, at 16:47, Leezarius wrote:
>>> Simon Thanks! >>> I used three different signal
>>> public var clicked:NativeSignal; >>> public var overed:NativeSignal; >>> public var outed:NativeSignal;
>>> But I was wrong when copying and did not change signal names when >>> initializing. >>> I understand that the signal is a wrapper, but I think it's a bad >>> situation. >>> In the following case, for example, I have only one array >>> var customArray:Array; >>> customArray=[1,1,1]; >>> customArray=[2,2,2]; >>> customArray=[3,3,3]; >>> And this array is [3,3,3]
>>> In the case of a signal I can add any number of events and a problem >>> with garbage collector or uncontrolled behavior of the object. >>> Thanks.
>>> On Oct 24, 7:03 pm, Simon Richardson <stickup...@gmail.com> wrote: >>>> The NativeSignal wraps addEventListener, so the changeState, overHandler, outHandler get passed to the native method. So when the view clicked all three methods would be called (this is expected). Ideally the gc would collect this when the view is removed and the class (which the native signals are in) is gc'd, but when this might happen is a guess.
>>>> My solution would be to use different variables for the the NativeSignals (nativeClicked, nativeRollOver, nativeRollOut, etc) and this would prevent the leak, but if this situation does occur then you could just use the view.removeEventListener(MouseEvent.CLICK, changeState), but then you have to rely on gc for the original signals being cleared.
>>>> But from what I'm seeing, I think you're trying to do the following:
>>>> public const signals : Vector.<NativeSignal> = new Vector.<NativeSignal>(3, true);
>>>> signals[0] = new NativeSignal(view, MouseEvent.CLICK, MouseEvent); >>>> signals[0].add(changeState); >>>> signals[1] = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent); >>>> signals[1].add(overHandler); >>>> signals[2] = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent); >>>> signals[2].add(outHandler);
>>>> If this is the aim, I would suggest making a immutable class that has 3 getters for each NativeSignal and having a method on it to determine how many signals are used in total. (get numListeners())
>>>> (other options exist as well, this is just how I would do it.)
>>>> Cheers >>>> si
>>>> On 24 Oct 2011, at 14:04, Leezarius wrote:
>>>>> Hi EveryBody! >>>>> I see signals and find strange situation:
>>>>> ... >>>>> public var clicked:NativeSignal;
>>>>> public function ButtonSound(_view:MovieClip) >>>>> { >>>>> view = _view; >>>>> init(); >>>>> }
>>>>> private function init():void >>>>> {
>>>>> clicked = new NativeSignal(view, MouseEvent.CLICK, MouseEvent); >>>>> clicked.add(changeState); >>>>> clicked = new NativeSignal(view, MouseEvent.ROLL_OVER, MouseEvent); >>>>> clicked.add(overHandler); >>>>> clicked = new NativeSignal(view, MouseEvent.ROLL_OUT, MouseEvent); >>>>> clicked.add(outHandler); >>>>> ...
>>>>> And its work! >>>>> My button duspatch all 3 state. >>>>> trace(clicked.numListeners)// output:"1" >>>>> This means the signal keeps copies of all assigned without the >>>>> possibility of their removal?