How to simulate Geolocation service AS3 - actionscript-3

I'm creating an app that is using Geolocation servioce on phone o send location/time data over the internet. And that is working just fine. Problem is that I cannot test it in Flashdevelop, cause Geolocation is not supported, so I have to upload every time new code and test it on phone. Is there any way to simulate Geolocation service in Flashdevelop? Or generally, on desktop PC?

Sorry for bothering ... I found out... quite simple answer was..
private function startLocating():void {
var myLat:Number=44.2343;
var myLong:Number=20.9432;
_geo = new Geolocation();
_geo.addEventListener(GeolocationEvent.UPDATE, Handler1 );
if (Geolocation.isSupported) {
if (!_geo.muted) {
_geo.setRequestedUpdateInterval(1000);
} else {
trace ("Location service not turned on.");
}
} else {
/* this code is working when Geolocation is not supported */
_geo.dispatchEvent(new GeolocationEvent(GeolocationEvent.UPDATE,false,false,myLat,myLong));
}
}
private function Handler1(ev:GeolocationEvent):void {
var latitude:Number = ev.latitude;
var longitude:Number = ev.longitude;
.....
}

Related

Adobe AIR Android FileStream issue

I tried to test blow code on Android device but i couldn't see any data in text fields. This code works well on AIR Desktop but in Android no. Is it difference between AIR FileStream function on Desktop and Android? Whats best cross platform code to save files and read write?
This code works on Adobe Animate CC Android Emulator.
import flash.filesystem.*;
var prefsFile:File;
[Bindable] var prefsXML:XML;
var stream:FileStream;
function appStart():void
{
prefsFile = File.applicationStorageDirectory;
prefsFile = prefsFile.resolvePath("preferences.xml");
readXML();
}
function readXML():void
{
stream = new FileStream();
if (prefsFile.exists) {
stream.open(prefsFile, FileMode.READ);
processXMLData();
}
else
{
saveData();
}
}
function processXMLData():void
{
prefsXML = XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
trace(prefsXML.Data1);
trace(prefsXML.Data2);
trace(prefsXML.Data3);
txt_D1.text = prefsXML.Data1;
txt_D2.text = prefsXML.Data2;
txt_D3.text = prefsXML.Data3;
}
function windowClosingHandler(event:Event):void
{
saveData();
}
function saveData():void
{
createXMLData();
writeXMLData();
}
function createXMLData():void
{
prefsXML = <preferences/>;
prefsXML.Data1 = 1;
prefsXML.Data2 = 2;
prefsXML.Data3 = 3;
}
function writeXMLData():void
{
var outputString:String = '<?xml version="1.0" encoding="utf-8"?>\n';
outputString += prefsXML.toXMLString();
outputString = outputString.replace(/\n/g, File.lineEnding);
stream = new FileStream();
stream.open(prefsFile, FileMode.WRITE);
stream.writeUTFBytes(outputString);
stream.close();
}
appStart();
That's the correct way, we use it for AIR app (Desktop, Android, iOS) to store user data on device/PC, File.applicationStorageDirectory as well. So your code is cross-platform, if it does not work on Android, you probably have some other issue, but your code looks fine.
To read/write data to File.applicationStorageDirectory you don't need any explicit permissions in app manifest as well.
If your Android version is 6.0 or more recent, you need to request permissions such as files or camera at runtime.
Ensure you have AIR 24.0 , with compiler option -swf-version=35, and do something like:
var permissionCheck : File = new File( "test") );
permissionCheck.addEventListener(PermissionEvent.PERMISSION_STATUS , function permissionStatusHandler( e : PermissionEvent ) :void
{
permissionCheck.removeEventListener(PermissionEvent.PERMISSION_STATUS , permissionStatusHandler);
if(e.status == PermissionStatus.GRANTED)
{
// save your file
}
else
{
showPermissionError();
}
});
try
{
permissionCheck.requestPermission();
}
catch(error : Error)
{
}
See the AIR release notes for more info such as handling the camera permission.
https://helpx.adobe.com/flash-player/release-note/fp_24_air_24_release_notes.html
Hope this helps.

Remote shared object not firing onSync method after update

I have game server, FMS 4.5 on Windows, already working prefect, and client apps were created in old CS4, and all is perfect.
Now I want to create a mobile app in AS3, and have a problem with remote shared object, which is working perfect in old flash program.
When users are logged into app, I'm receiving an update with onSync method. But whenever remote shared object is updated, I'm not receiving updates.
for example, on client, where I have main_nc as netConnection object:
var ncu_so:SharedObject = SharedObject.getRemote("Zusers", main_nc.uri, false);
ncu_so.addEventListener(SyncEvent.SYNC, syncNCU);
ncu_so.client=this;
ncu_so.connect(main_nc);
private function syncNCU(e:SyncEvent):void {
........
//here I receive new info....
}
and sample on server...
application.onAppStart = function(){
this.Zusers_so = SharedObject.get( "Zusers", false );
...........
}
function sampleUserEnter(client) {
var t=new Object();
t.username=client.username;
application.Zusers_so.setProperty(client.id,t);
//this one call is synced with app
}
function sampleChangeName(client,newName) {
var t=application.Zusers_so.getProperty(client.id);
t.username=newName;
application.Zusers_so.setProperty(client.id,t);
//this IS NOT syncing with app
}
As I said, this code is working with old flash software, but wont update when using AS3. Any idea?
I found an easy solution. Not sure why it works but it works....
var ncu_so:SharedObject = SharedObject.getRemote("Zusers", main_nc.uri, false);
ncu_so.addEventListener(SyncEvent.SYNC, syncNCU);
//I add the listener for checking status
ncu_so.addEventListener(NetStatusEvent.NET_STATUS, statusNCU);
ncu_so.client=this;
ncu_so.connect(main_nc);
private function syncNCU(e:SyncEvent):void {
........
//here I receive new info....
}
//In function for NetStatus event, I just set a simple property
//which I do not use in the app..
//and sunchronization start working as usual after initial sync
private function statusNCU(ev:NetStatusEvent):void {
if (ev.info.code == "NetConnection.Connect.Success") {
ncu_so.setProperty("anyPropertyName",new Date());
}
}

AngularJs based webApp which works offline

I am working on a check in app, that uses a SQL server database to store and get the People
if the app is online, and uses local storage to store people when it is offline , which will push these changes into the database once it comes back online.
my controller currently goes like this
function DemoController($scope,localStorageService,$http,$resource,$interval)
{
$scope.online = "";
$scope.checkConnection=function()
{
check=window.navigator.onLine;
if(!check)
{
$scope.online="offline";
return false;
}
else
{
$scope.online="online";
return true;
}
}
if($scope.checkConnection() == true){
$scope.Get = function(){
$http.get(url).success{function(res)
{
$scope.People = res;
$scope.setPeople();
}
}
//basically the edit and delete function for those people
$scope.setPeople = function() {};
$scope.deletePeople = function(){};
}
else if ($scope.checkConnection == false)
{
// use same methods/functions but with local storage
$scope.pushAll = function (){ %http.put(url)}
//here is the part i do not understand
if checkConnection switches from offline to online
{
$scope.pushAll();
}
}
$scope.intervalCheck = function()
{
var intervalPromise;
intervalPromise = $interval($scope.checkConnection(), 250);
};
$scope.intervalCheck();
}
And the other problem is that even if it switches from online to offline or vise-versa I doesn't switch the methods it uses (online/offline methods).
I am not sure if there is a proper way to actually write this but i Hope there is, if this is too vague I can edit the post with more details.
I think you should try using cookies for that. to store offline data
but large data in cookies, is discouraged so be careful.

Using Gamepads in Google Dart

I'm looking for code examples for the Gamepad API for Google Dart.
I've tried relying on the API doc directly and attempted to write out an instance for it.
//Gamepad Example:
Gamepad g = new Gamepad();
g.id.toString(); // This doesn't seem to return anything...
If anyone has any code examples for this that would be fantastic!
I tried this and it worked for me :
import "dart:html";
main(){
window.animationFrame.then(runAnimation);
}
runAnimation(timestamp){
var gamepads = window.navigator.getGamepads();
for (var pad in gamepads)
{
if(pad != null){
querySelector("#buttons").setInnerHtml("${pad.buttons.join(" ")}</br>${pad.axes.join(" ")}");
}
}
window.requestAnimationFrame(runAnimation);
}
I don't have a gamepad to try but
Gamepad g = new Gamepad();
doesn't work because Gamepade has no public constructor.
Try
var gp = window.navigator.getGamepads();
//or
// haven't tried because I don't know how to provoke this event without a gamepad
window.on['gamepadconnected'].listen((e) {
var gamepad = e.gamepad;
});
instead.
I get an empty list so I can't examine more.
see also:
- https://developer.mozilla.org/en-US/docs/Web/Guide/API/Gamepad
- https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html

Adobe Air and Dropbox

I'm trying to integrate dropbox into my BB Playbook app using adobe air in flashbuilder 4.6. I got the API from http://code.google.com/p/dropbox-as3/wiki/EXAMPLES and I'm also using that example.
public function getRequestToken():void
{
dropAPI.requestToken();
var handler:Function = function (evt:DropboxEvent):void
{
dropAPI.removeEventListener(DropboxEvent.REQUEST_TOKEN_RESULT, handler);
var obj:Object = evt.resultObject;
reqTokenKeyLabel.text = obj.key;
reqTokenSecretLabel.text = obj.secret;
// goto authorization web page to authorize, after that, call get access token
if (oauthRadioBtn.selected) {
Alert.show(dropAPI.authorizationUrl);
}
};
dropAPI.addEventListener(DropboxEvent.REQUEST_TOKEN_RESULT, handler);
if (!dropAPI.hasEventListener(DropboxEvent.REQUEST_TOKEN_FAULT)) {
dropAPI.addEventListener(DropboxEvent.REQUEST_TOKEN_FAULT, faultHandler);
}
}
This executes as expected but I don't know how to go further, I tried sending the user to the link generated and I allow the application but the get access token still fails. I feel like there is missing code, how does my application know what the access token is? should I not be getting something back from dropbox when the user allows the application?
Once the user has accepted the app in the web browser you should call this function in order to get the access token and secret:
public function getAccessToken():void{
dropAPI.accessToken();
var handler:Function = function (evt:DropboxEvent):void{
dropAPI.removeEventListener(DropboxEvent.ACCESS_TOKEN_RESULT, handler);
var obj:Object = evt.resultObject;
myAccessToken = obj.key;
myAccessSecret = obj.secret;
};
dropAPI.addEventListener(DropboxEvent.ACCESS_TOKEN_RESULT, handler);
if (!dropAPI.hasEventListener(DropboxEvent.ACCESS_TOKEN_FAULT)) {
dropAPI.addEventListener(DropboxEvent.ACCESS_TOKEN_FAULT, faultHandler);
}
}
Once you have them you can save them for future use. After that you have establish connection with Dropbox.
I hope this will help you