fljot / Gestouch

Gestouch: multitouch gesture recognition library for Flash (ActionScript) development.
MIT License
356 stars 84 forks source link

Starling.dispose() loses Gestouch swipe #89

Closed sankar2389 closed 9 years ago

sankar2389 commented 9 years ago

I use starling for book reader app. When i change the book, i'm disposing the current starling and create new starling instance.But when I created new starling, Gestouch doesn't works.

How to restart gestouch for a new starling instance

gestouch code.

gallery.addEventListener(MouseEvent.CLICK,book);

onKeyDown(event:KeyboardEvent):void
        {
            if(event.keyCode == Keyboard.BACK )
            {
                event.preventDefault();
                event.stopImmediatePropagation();
                this.starling.stop();
                this.starling.dispose();
                this.starling = null;
}

}

book(e:MouseEvent):void
        { 
this.starling = new Starling(RacTestApp,stage,viewPort);
Gestouch.inputAdapter ||= new NativeInputAdapter(stage);
        Gestouch.addDisplayListAdapter(starling.display.DisplayObject, new StarlingDisplayListAdapter());
        Gestouch.addTouchHitTester(new StarlingTouchHitTester(this.starling), -1);
this.starling.start();
}

thank you

fljot commented 9 years ago

Please try this branch https://github.com/fljot/Gestouch/tree/features/71-fix-initialization – I have refactored some initialization stuff – see changelog for instructions: https://github.com/fljot/Gestouch/blob/features/71-fix-initialization/CHANGELOG.md I need some confirmation that it works=)

Don't re-do all this initialization stuff when you create another Starling instance. Setup input adapter and add display list adapter only once. And regarding hit-tester – just keep a reference to once created and added StarlingTouchHitTester and update starling reference there Oh snap StarlingTouchHitTester has no way to update starling property – it's set in constructor only... Well, then on dispose call:

Gestouch.removeTouchHitTester(this.myStarlingTouchHitTester);

and when create starling do:

this.myStarlingTouchHitTester = new StarlingTouchHitTester(this.starling);
Gestouch.addTouchHitTester(this.myStarlingTouchHitTester, -1);
sankar2389 commented 9 years ago

Thanks Fljot, now it works :)

fljot commented 9 years ago

@sankar2389 and branch code – all good?