Event exit the application - actionscript-3

I create app for android. I need catch event exit the application. On the PC all work - I catch exit event. When I testing on the devise event didn't work.
What kind of event it is? Please help.

Listening to the NativeApplication's EXITING event should work...
NativeApplication.nativeApplication.addEventListener(Event.EXITING, applicationExitHandler);
private function applicationExitHandler(event:Event):void
{
trace("exit")
}
However, the app on Android may be going into the background, and not actually exiting. To listen for this, use the DEACTIVATE event...
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, applicationDeactivateHandler);
private function applicationDeactivateHandler(event:Event):void
{
trace("background")
}
Likewise, listen for the ACTIVATE event when the app comes to the foreground.

Related

Chrome (open) Shadow DOM Events Not Reaching Host

I'm running Chrome 56.0.x (corporate mandate), along with Polymer 2. My sample component isn't doing anything fancy; just raising a CustomEvent after making a simple AJAX call. I'm setting "bubbles":true and "composed":true, and I can validate that the event is dispatched and that my host is listening for the event properly.
sample-component.html
raiseDataRetrievedEvent() {
this.dispatchEvent(
new CustomEvent('sample-component-data-retrieved', {
bubbles: true,
composed: true,
detail: { data: "loading complete" }
}));
}
However, the events never make it out of the Shadow DOM to my host page listeners.
index.html
// Listen to Custom event from Sample Component
document.querySelector('sample-component').addEventListener('sample-component-data-retrieved', function (e) {
alert(e.detail);
console.log(e.detail);
});
Interestingly enough, when I have a user initiated event (e.g. click) trigger this CustomEvent, it happily makes its way through the Shadow DOM to my listener. It's just the events that are programmatically created that are getting stuck.
UPDATE 1
This issue only seems to manifest itself when I'm serving my site locally (e.g. http://localhost, http://127.0.0.1, http://COMPUTERNAME). When I publish the site to another host, all the events seem to propagate as expected. Feels to me more like a Chrome issue at this point...
UPDATE 2
I put my code out on github here: https://github.com/davidfilkins/polymer-test.
I did some more testing and the results keep getting weirder... when I'm developing / testing in Chrome, I almost always have Dev Tools open. I noticed strangely enough that when my tools are open, that the event isn't captured by the host page (index.html)... but this seems to only happen locally. When I close tools and load the page locally, the events bubble properly... But this is only for the dispatched events that aren’t tied to an explicit user action; those all seem to work regardless of the tools being open or not.
When I access the simple Azure app that I created - http://samplepolymertwo.azurewebsites.net/index.html - all events are bubbled / captured regardless of whether the tools are open.
No clue if this is fixed in more current versions of Chrome or not.
The culprit was all timing...
In Chrome, with Dev Tools open, running on localhost, the event was dispatched from the component before the event listener was wired up on the host page.
Event Timing
I suppose the ideal scenario would be for the web component to wait until the event listener on the host had been wired up before broadcasting the event.

How do i make the game wait until a funcion is called?

I was creating a script and i want to know how do i make the game wait until a funcion is called
If someone awnser me,ill be thankful
Firstly do not use loops, use events!
To wait for an event to happen you can use the wait method, like so:
print("Starting to wait for touch")
workspace.Part.Touched:Wait()
print("Touched!")
This will wait for the part to be touched before it continues the script.
But ofcourse, other scripts will still run, the game is not "paused", it is just that script's execution that is suspended until the event is fired.
You can also make custom "wait for call" by using for example a BoolValue like so:
local WaitObject = Instance.new("BoolValue")
function WaitOn()
WaitObject.Changed:Wait()
end
function StopWait()
WaitObject.Value = not WaitObject.Value
end
You can also place the BoolValue in the game and do the wait and stop wait in separated scripts.
If you do it in same script, remember to use different threads

Wait for App to idle after Interruption

I have a ViewController that will request access to location services on init via
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
[_locationManager requestWhenInUseAuthorization];
}
This triggers the "Allow app to access your location while you use the app?"-alert.
I use [self addUIInterruptionMonitorWithDescription:handler:] to react to this. I am encountering the following problem: after dismissing the request-dialog, the ui-test does not continue. The alert is dismissed, but Xcode waits for the app to become idle, but it looks like the app is idle:
t = 67.35s Wait for app to idle
The test fails, because the app is stuck here. If i tap into the simulator, Xcode logs.
t = 72.27s Synthesize event
and continues the test.
Is there a reason, why Xcode tries to wait for the app? A workaround seems to be to tell Xcode that the UI changed or an event happened. Is there a way to trigger this?
After presenting the alert you must interact with the interface. This is a known bug with Xcode 7.2. Simply tapping the app works just fine, but is required.
addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
alert.buttons["Allow"].tap()
return true
}
app.buttons["Find Games Nearby?"].tap()
app.tap() // need to interact with the app for the handler to fire
XCTAssert(app.staticTexts["Authorized"].exists)
See my blog post for more information.

Chromecast event for device disconnect (sender)

Is there event that will notify a sender app when the use selects "stop cast" from within the chrome extension?
I've a chrome sender app get's in a limbo state if the user chooses to stop the cast from the extension instead of the app cast button.
EDIT:
This is some relevant code:
CastPlayer.prototype.onMediaDiscovered = function (how, mediaSession) {
this.currentMediaSession = mediaSession;
// ...
this.currentMediaSession.addUpdateListener(this.onMediaStatusUpdate.bind(this));
// ...
};
CastPlayer.prototype.onMediaStatusUpdate = function (e) {
console.log(e);
};
Have you tried Session.addUpdateListener(listener) ? I think the listener will be notified when the session is no longer alive.
It seems Google developers are pretty aware of that! :D
They've just update their senders sample code with a commit that is exactly what seems you're looking for: Added session update listener to handle disconnect by clicking cast extension
There's also another commit with the same text in another sample but with less code, here you have: https://github.com/googlecast/CastHelloVideo-chrome/commit/776559c9aaf16d7d82c62ee4dea611b6177ac217

AS3: Is there anyway to tell if connection has been lost during FileReference.upload()?

Observing FileReference.upload() I notice that if I'm uploading large file (big enough for upload to last for some time) and cut the connection (by pulling out LAN cable for example) in the middle of upload, Flash doesn't report an error... In fact it continues to fire Progress events all the way to "successful" completion.
Is this a bug? Shouldn't there be an exception thrown or error event fired?
Accordning to the documentation on FileReference.upload() it should invoke an IOErrorEvent when such a thing happens.
Try listening for an IOErrorEvent
yourFilereference.addEventListener(IOErrorEvent.IO_ERROR, error)
function error(e:IOErrorEvent):void
{
//Do something
}