Permalink
Browse files

Update for new API + one more example/test

  • Loading branch information...
1 parent 1b9573b commit 0e862b9ca9c952f2fde02a679da253a76061daf9 @fljot committed Jul 4, 2012
View
Binary file not shown.
@@ -1,13 +1,15 @@
package org.gestouch.examples.model
{
+ import org.gestouch.examples.starling.ConflictGesturesExample;
+ import org.gestouch.examples.starling.TransformedViewportExample;
import org.gestouch.examples.views.ConflictGesturesView;
import org.gestouch.examples.views.DependentSwipingGesturesView;
import org.gestouch.examples.views.DependentTapGesturesView;
import org.gestouch.examples.views.LongPressGestureAdvancedView;
import org.gestouch.examples.views.LongPressGestureView;
import org.gestouch.examples.views.PanGestureView;
import org.gestouch.examples.views.RotateGestureView;
- import org.gestouch.examples.views.StarlingConflictGesturesView;
+ import org.gestouch.examples.views.StarlingExampleViewBase;
import org.gestouch.examples.views.SwipeGestureView;
import org.gestouch.examples.views.TapGestureUsageView;
import org.gestouch.examples.views.TapGestureView;
@@ -36,10 +38,9 @@ package org.gestouch.examples.model
,{label: "Conflicts Resolution Example", viewClass: ConflictGesturesView}
,{label: "Dependent Tap Gestures Example", viewClass: DependentTapGesturesView}
,{label: "Dependent Swiping Gestures Example", viewClass: DependentSwipingGesturesView}
- ,{label: "Starling: Conflicts Example", viewClass: StarlingConflictGesturesView}
+ ,{label: "Starling: Conflicts Example", viewClass: StarlingExampleViewBase, starlingMainClass: ConflictGesturesExample}
+ ,{label: "Starling: Transformed Viewport Example", viewClass: StarlingExampleViewBase, starlingMainClass: TransformedViewportExample}
]
);
-
- public var lastViewTitle:String;
}
}
@@ -1,53 +0,0 @@
-package org.gestouch.examples.starling
-{
- import flash.display.Sprite;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.geom.Rectangle;
- import org.gestouch.core.GesturesManager;
- import org.gestouch.core.IGesturesManager;
- import org.gestouch.extensions.starling.StarlingDisplayListAdapter;
- import org.gestouch.extensions.starling.StarlingInputAdapter;
- import starling.core.Starling;
- import starling.display.DisplayObject;
- import starling.events.ResizeEvent;
-
-
-
- [SWF(backgroundColor="#FFFFFF", frameRate="60", width="640", height="480")]
- /**
- * @author Pavel fljot
- */
- public class StarlingExample extends Sprite
- {
- private var starling:Starling;
-
-
- public function StarlingExample()
- {
- stage.scaleMode = StageScaleMode.NO_SCALE;
- stage.align = StageAlign.TOP_LEFT;
-
- Starling.multitouchEnabled = true; // useful on mobile devices
- Starling.handleLostContext = true; // deactivate on mobile devices (to save memory)
-
- starling = new Starling(StarlingRoot, stage);
- starling.enableErrorChecking = false;
- starling.stage.addEventListener(ResizeEvent.RESIZE, starling_resizeHandler);
- starling.start();
-
- var gesturesManager:IGesturesManager = GesturesManager.getInstance();
- gesturesManager.addDisplayListAdapter(starling.display.DisplayObject, new StarlingDisplayListAdapter());
- gesturesManager.addInputAdapter(new StarlingInputAdapter(starling));
- }
-
-
- private function starling_resizeHandler(event:ResizeEvent):void
- {
- var rect:Rectangle = new Rectangle(0, 0, event.width, event.height);
- starling.viewPort = rect;
- starling.stage.stageWidth = rect.width;
- starling.stage.stageHeight = rect.height;
- }
- }
-}
@@ -1,7 +1,6 @@
package org.gestouch.examples.starling
{
- import fr.kouma.starling.utils.Stats;
-
+ import starling.core.Starling;
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;
@@ -11,6 +10,7 @@ package org.gestouch.examples.starling
import starling.events.TouchPhase;
import starling.textures.Texture;
+ import flash.geom.Rectangle;
import flash.utils.setTimeout;
@@ -23,21 +23,29 @@ package org.gestouch.examples.starling
private static const backButtonImage:Class;
private var backButton:Image;
- private var stats:Stats;
public function StarlingExampleBase()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
+
+
+ public function resize(width:int, height:int):void
+ {
+ const rect:Rectangle = new Rectangle(0, 0, width, height);
+ const starling:Starling = Starling.current;
+ starling.viewPort = rect;
+ starling.stage.stageWidth = rect.width;
+ starling.stage.stageHeight = rect.height;
+
+ onResize(starling.stage.stageWidth, starling.stage.stageHeight);
+ }
protected function onResize(width:Number, height:Number):void
{
- if (stats)
- {
- stats.x = width - stats.width;
- }
+
}
@@ -50,34 +58,16 @@ package org.gestouch.examples.starling
protected function init():void
- {
- stage.addEventListener(ResizeEvent.RESIZE, stage_resizeHandler);
-
+ {
backButton = new Image(Texture.fromBitmap(new backButtonImage()));
backButton.x = backButton.y = 3;
backButton.scaleX = backButton.scaleY = 2;
backButton.addEventListener(TouchEvent.TOUCH, backButton_touchHandler);
addChild(backButton);
-// stats = new Stats();
-// addChild(stats);
-
- setTimeout(stage_resizeHandler, 1);
+ setTimeout(resize, 1, stage.stageWidth, stage.stageHeight);
}
-
-
- private function stage_resizeHandler(event:ResizeEvent = null):void
- {
- if (event)
- {
- onResize(event.width, event.height);
- }
- else if (stage)
- {
- onResize(stage.stageWidth, stage.stageHeight);
- }
- }
-
+
private function backButton_touchHandler(event:TouchEvent):void
{
@@ -0,0 +1,63 @@
+package org.gestouch.examples.starling
+{
+ import starling.textures.Texture;
+ import starling.core.Starling;
+ import starling.display.Image;
+
+ import com.greensock.TweenMax;
+
+ import org.gestouch.events.TapGestureEvent;
+ import org.gestouch.gestures.Gesture;
+ import org.gestouch.gestures.TapGesture;
+
+ import flash.geom.Rectangle;
+
+
+ /**
+ * @author Pavel fljot
+ */
+ public class TransformedViewportExample extends StarlingExampleBase
+ {
+ [Embed(source="/assets/images/YellowSquare.png")]
+ private static const yellowAsset:Class;
+
+
+ public function TransformedViewportExample()
+ {
+ super();
+ }
+
+
+ override public function resize(width:int, height:int):void
+ {
+ const rect:Rectangle = new Rectangle(100, 100, width - 200, height - 200);
+ const starling:Starling = Starling.current;
+ starling.viewPort = rect;
+ starling.stage.stageWidth = rect.width;
+ starling.stage.stageHeight = rect.height;
+
+ onResize(starling.stage.stageWidth, starling.stage.stageHeight);
+ }
+
+
+ override protected function init():void
+ {
+ super.init();
+
+ var image:Image = new Image(Texture.fromBitmap(new yellowAsset()));
+ //image.width = image.height = Math.min(stage.stageWidth, stage.stageHeight) / 3;
+ image.y = 50;
+ addChild(image);
+
+ var tap:TapGesture = new TapGesture(image);
+ tap.addEventListener(TapGestureEvent.GESTURE_TAP, onTap, false, 0, true);
+ }
+
+
+ private function onTap(event:TapGestureEvent):void
+ {
+ trace("tap");
+ TweenMax.to((event.target as Gesture).target, 0.5, {bezierThrough:[{alpha:0.1}, {alpha:1}]});
+ }
+ }
+}
@@ -4,8 +4,6 @@ package org.gestouch.examples.views
import spark.components.View;
import spark.events.ViewNavigatorEvent;
- import org.gestouch.examples.model.ExamplesModel;
-
import mx.core.UIComponent;
import mx.events.FlexEvent;
import mx.events.ResizeEvent;
@@ -25,9 +23,6 @@ package org.gestouch.examples.views
private var backButton:Button;
private var settingsButton:Button;
- [Bindable]
- protected var dataModel:ExamplesModel;
-
public function ExampleViewBase()
{
@@ -85,13 +80,11 @@ package org.gestouch.examples.views
protected function onViewActivate():void
{
- if (!dataModel && data)
- {
- dataModel = data as ExamplesModel;
-
- if (dataModel.lastViewTitle)
+ if (data)
+ {
+ if (data.hasOwnProperty("title"))
{
- title = dataModel.lastViewTitle;
+ title = data.title;
}
}
}
@@ -9,6 +9,8 @@
>
<fx:Script>
<![CDATA[
+ import mx.utils.ObjectUtil;
+ import org.gestouch.examples.model.ExamplesModel;
import mx.core.IFlexDisplayObject;
import spark.components.Button;
import spark.events.IndexChangeEvent;
@@ -22,6 +24,9 @@
private var debuggerButton:Button;
+ [Bindable]
+ private var dataModel:ExamplesModel;
+
override protected function init():void
{
@@ -30,6 +35,8 @@
debuggerButton.setStyle("icon", debuggerIconAsset);
debuggerButton.addEventListener(MouseEvent.CLICK, debuggerButton_clickHandler);
// actionContent = [debuggerButton];
+
+ dataModel = data as ExamplesModel;
}
@@ -45,10 +52,14 @@
{
if (event.newIndex > -1)
{
- var exampleName:String = list.selectedItem.label;
- dataModel.lastViewTitle = exampleName;
+ const data:Object = {};
+ for (var k:* in list.selectedItem)
+ {
+ data[k] = list.selectedItem[k];
+ }
+ data.title = list.selectedItem.label;
var viewClass:Class = list.selectedItem.viewClass;
- navigator.pushView(viewClass, dataModel);
+ navigator.pushView(viewClass, data);
}
}
@@ -1,24 +0,0 @@
-package org.gestouch.examples.views
-{
- import org.gestouch.examples.starling.ConflictGesturesExample;
-
-
- /**
- * @author Pavel fljot
- */
- public class StarlingConflictGesturesView extends StarlingExampleViewBase
- {
- public function StarlingConflictGesturesView()
- {
- super();
- }
-
-
- override protected function init():void
- {
- starlingMainClass = ConflictGesturesExample;
-
- super.init();
- }
- }
-}
Oops, something went wrong.

0 comments on commit 0e862b9

Please sign in to comment.