TouchEvent.TOUCH_MOVE not fired on MS Surface - actionscript-3

I'm developing an AIR app prototype on Surface, and I'm noticing that TouchEvent.TOUCH_MOVE is not fired as expected....
I've built a quick debug application:
private var tf:TextField;
public function init():void{
trace("init");
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
tf = new TextField();
tf.multiline = true;
tf.width = 800;
tf.height = 2000;
this.stage.addChild(tf);
tf.text = "Test";
var touch:Sprite = new Sprite;
touch.graphics.beginFill(0xFFFF00,0.3);
touch.graphics.drawRect(0,0,800,200);
touch.graphics.endFill();
this.stage.addChild(touch);
touch.addEventListener(TouchEvent.TOUCH_BEGIN, updateTF);
touch.addEventListener(TouchEvent.TOUCH_END, updateTF);
touch.addEventListener(TouchEvent.TOUCH_MOVE, updateTF);
touch.addEventListener(TouchEvent.TOUCH_OVER, updateTF);
touch.addEventListener(TouchEvent.TOUCH_TAP, updateTF);
touch.addEventListener(TouchEvent.TOUCH_ROLL_OUT, updateTF);
touch.addEventListener(TouchEvent.TOUCH_ROLL_OVER, updateTF);
}
private function updateTF(event:TouchEvent):void
{
trace(event);
tf.appendText("\n event:" + event);
}
...and it confirms me no TouchEvent.TOUCH_MOVE is being fired.
What could be the issue?
Thank you

So, I didn't solve the issue but I found the explication and a workaround.
This is bug on AIR 3.8 on Windows 8.
Just install a previous version of AIR.
Hope it helps someone :)

You can use MouseEvents instead of touch events for Microsoft Surface. Because adobe not yet released for Microsoft Surface touch device(see adobe labs).
Normally all touch events fall back to mouse events so you can try with Mouse-events. It works well for me . But not sure about Mouse Move event but it works for touch begin and touch end events to mousedown and mouseup events.

Related

Audio stream reconnect in as3

I am using the following code in a swf created with Flash CS6:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var customClient:Object = new Object();
ns.client = customClient;
ns.play("http://streamserver3.us:7018/stream?type=.flv");
It plays an Icecast audio streaming.
How could I do to reconnect automatically (if the internet connection drops, etc.)?
Thank you very much for your help!
Sincerely.
See if any of these NetStreamInfo options can help you detect a connection drop:
Try using a timer that fires every two seconds where the responding function checks if there has been a change (ie: amount of incoming data has become zero).
Maybe check with ns.info.dataBytesPerSecond but explore the descriptions of other methods in that linked Info Class. Use an If statement to check input has not become zero or Else (if now zero) run your function that reconnects (does usual ns.stop(); & ns.play( url ); etc..).
Thank you very much for your help. I have found a solution that works and I would like to share:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var customClient:Object = new Object();
ns.client = customClient;
ns.play("http://xxxxxxxxx/stream?type=.flv");
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
function netStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code)
{
case 'NetStream.Play.Stop' :
MovieClip(this.root).gotoAndPlay(1, "Scene 2");
break;
case "NetStream.Play.StreamNotFound" :
MovieClip(this.root).gotoAndPlay(1, "Scene 2");
break;
}
}
I have created a new scene "Scene 2" with the following code:
MovieClip(this.root).gotoAndPlay(1, "Scene 1");
Now if the stream (internet or server connection) is lost, the player will reconnect automatically to the stream.
Working great!
Thank you very much for your ideas!
Regards

Gestouch is not working

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
Hey Guys I got the answer:
OnKeydown(){
Gestouch.removeTouchHitTester(this.myStarlingTouchHitTester);
}
book(){
this.myStarlingTouchHitTester = new StarlingTouchHitTester(this.starling);
Gestouch.addTouchHitTester(this.myStarlingTouchHitTester, -1);
}
We have to add and remove TouchHitTester, if we are using multiple starling instances.

Restarting sound files in AS3

stop();
var mySound:Sound = new MyFavSong();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
myChannel = mySound.play();
pause_btn1.addEventListener(MouseEvent.CLICK, onClickPause);
function onClickPause(e:MouseEvent):void
{
lastPosition = myChannel.position;
myChannel.stop();
}
play_btn1.addEventListener(MouseEvent.CLICK, onClickPlay);
function onClickPlay(e:MouseEvent):void
{
myChannel = mySound.play(lastPosition);
}
I am trying to make a restart button however everything I have read is not correctly working on bringing it back to the start of the sound. I am not really great with flash so I made it as simple as I could. Any and all help would be great.
Your code is fine and that's the correct way to implement a pause/play method in as3.
That means the problem is elsewhere. Print lastPosition at the start of your onClickPlay function. Is it printing something other than 0?
Take this as a comment. This thing only lets me post answers.

Loader Complete event does not work with browser (AS3)

Im trying to load an image in a movie clip and change its size as follow:
var loader:Loader = new Loader();
public function setProfilePicture(url:String){
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplte);
loader.load(new URLRequest(url));
addChild(loader);
}
protected function onComplte(event:Event):void
{
EventDispatcher(event.target).removeEventListener(event.type, arguments.callee);
var image:DisplayObject = (event.target as LoaderInfo).content;
image.width = 132;
image.height = 132;
}
The code above works fine when I execute it with adobe flash CS5, but when I try to open it with a browser (e.g. Chrome), the size of images does not change to 132x132. I tried to put addChild(loader) in the onComplete function, but in this time when I open it with a browser, the image won't be even loaded, while executing with adobe flash CS5 remains as before.
My suggestion is that when we open it by browser, the function onComplete does not work, but WHY???
Any idea will be appreciated.
Try this hack:
protected function onComplte( event:Event ):void {
EventDispatcher( event.target ).removeEventListener( event.type, arguments.callee );
var loaderInfo:LoaderInfo = LoaderInfo( event.target );
loaderInfo.loader.scaleX = 132 / loaderInfo.width;
loaderInfo.loader.scaleY = 132 / loaderInfo.height;
}
check this link: actionscript3 (flash) don't load images form user file in chrome
Verify that it works in a different browser other than chrome. This is most likely the pepper flash problem in chrome
I played with your onComplte function and somehow the content property of LoaderInfo is not accessible from in there. If all else fail, the size of the image can still be controlled from within setProfilePicture by scaling the Loader:
public function setProfilePicture(url:String){
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplte);
loader.load(new URLRequest(url));
loader.scaleX = 10; ////
loader.scaleY = 10; ////
addChild(loader);
}

NetStream.publish Webcam to FMS working in standalone player, but not in browser

I am trying to publish the video of a webcam to a Flash Media Server 2.
My code is working in the Flash standalone player (tested with 10.0 and 10.2), but not in the browser plugin (tested with 10.2, both in IE and Opera.
The connection to my FMS is working successfully, but after the publish, nothing happens, I never get the NetStream.Publish.Start Event. On the server I can see the connection in the management console, even the stream in the streams tab. But I cannot connect to that strea.
Anybody an idea what could be going wrong?
NetConnection.defaultObjectEncoding = ObjectEncoding.AMF0; // needed to get correct connection to FMS2
private function netStatusHandler(event:NetStatusEvent):void {
output.appendText("\n" + event.info.code);
switch (event.info.code) {
case "NetConnection.Connect.Success":
output.text = ("Connection successful, streaming camera...");
connectCamera();
break;
case "NetConnection.Connect.Failed":
break;
case "NetStream.Play.StreamNotFound":
break;
case "NetStream.Publish.Start":
output.appendText("\nPublishing video!");
break;
}
}
private function connectCamera(ev:Event = null):void {
var stream:NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.attachCamera(camera);
videoURL = createGUID();
stream.publish(videoURL, "live");
output.text = "publish stream...";
}
Ok, I found what my problem is here:
I declare the reference to the stream variable inside the connectCamera function:
private function connectCamera(ev:Event = null):void {
var stream:NetStream = new NetStream(connection);
}
So stream is only declared inside the scope of that function.
This doesn't seem to be a problem in the standalone player, but it is in the browser plugin. The browser plugin seems to do a much more thourough job on the garbage collector, garbage collecting my stream after the function has executed.
So what I have to do is declare the stream variable outside of the function scope, inside the class scope.
var stream:NetStream;
private function connectCamera(ev:Event = null):void {
stream = new NetStream(connection);
}
You should always declare stuff that you need later as a field on your class, and not inside a function. You just never know when GC might clean up that stuff.