01-03-2011 12:47 PM
Hi,
When I tested on my app on simulator, sometime, it exits "by itself".
My code did not have any close() window or any exit code.
This seems bugs, but on debug mode, I don't see any error message ...
My app should very small, so, I don't think any memory low and system force exit issue.
Does anyone have such problem too? ( How to debug ? )
Thanks,
01-03-2011 12:52 PM
It is most likely crashing in the simulator. See if you can reproduce the runtime error in AIR which will give verbose error messages. If it only seems to occur on the simulator, there are lots of threads in this forum that covers how to run your application in the simulator with remote debug back to your local computer that will show trace information and hopefully when an exception is thrown.
01-03-2011 12:57 PM
I actually added throw error code on my app to force it crash for testing, and I did see the debug mode work very well to report my testing error.
The situation now is, it "crash?" on debug mode and without any error back to my local computer...
( which seems no any exception happend and it is just "crash" and exit )
01-03-2011 01:12 PM
This is drving me crazy... I think that it is related to event stuff.
In fact, instead of each object has its own custom event. I create a EventCenter.
All events is dispatch via EventCenter, and all views are listener via EventCenter too.
In this way, all objects are independent and loose couple.
Since I am newbis on event stuff. I am not 100% sure the code is correct or not.
( it may related to the strange "crash" without exception ?? )
Please let me know if you find any problem on below code.
Thank you for your help.
import flash.events.Event;
import flash.events.EventDispatcher;
public class EventCenter
{
private static var eventDispatcher:EventDispatcher = new EventDispatcher();
public static function dispatchEvent(event:Event):Boolean
{
return eventDispatcher.dispatchEvent(event);
}
public static function addEventListener(type:String, listener:Function):void
{
eventDispatcher.addEventListener(type, listener);
}
public static function removeEventListener(type:String, listener:Function):void
{
eventDispatcher.removeEventListener(type, listener)
}
}
01-03-2011 01:51 PM
How are all your objects and views accessing this class? Is it instantiated just once in your application? Are you using it as a singleton or used within a singleton?
I guess if you want a single path way, I would extend EventDispatcher to EventCenter and have it as a singleton. But you might have something else in mind for this.
01-03-2011 02:02 PM
all my object are use its static method and never instance it.
I will try your suggestion... base on your suggestion, the code will be like....
public class EventCenter extends EventDispatcher {
private static var _instance:EventCenter = new EventCenter();
public static get function instance():EventCenter { return _instance; }
And all object will access via like : EventCenter.instance.addListener ( removeListener, dispatchEvent ... etc)
Is that your thinking to implement singleton EventCenter ?
Thanks.
01-03-2011 02:07 PM
base on your suggestion, my new code is like ....
import flash.events.EventDispatcher;
public class EventCenter extends EventDispatcher
{
private static const _instance:EventCenter = new EventCenter();
public static get function instance():EventCenter
{
return _instance;
}
}
01-03-2011 02:12 PM
Yes, that is what I had in mind, but does that help the termination issue? Or is it something else?
01-03-2011 02:14 PM
I believe your instance method should look like this:
////////////////////////////////////////////////////////////////////////// public static function get instance() : EventCenter
{ if( _instance == null ) // first time { _instance = new EventCenter(); } return _instance; }
But your method might work too. I'm just use in doing this way.
01-03-2011 02:41 PM
Hi jtegen,
I think that I "found" the problem; the problem is not on EventCenter.
The problem may on the persistence data stuff ( which I think that I copied your code from some discussion thread..., ).
The persistence is using simple xml data like code below.
The persistence works fine, it did save and load back data.
But, I think they may also related to terminate issue.
When I comment out the content of save() and load()... No more terminate issue....
I still cannot find out what's wrong on save() and load().
public function save():void
{
var fileStream:FileStream = new FileStream();
try
{
var file:File = File.applicationStorageDirectory.resolvePath(CONFI G_FILE_NAME);
fileStream.open(file, FileMode.WRITE);
var output:String = '<?xml version="1.0" encoding="utf-8"?>' + File.lineEnding;
output += '<config>' + File.lineEnding;
output += '<my_data>' + some_data + '</my_data>' + File.lineEnding;
output += '</config>' + File.lineEnding;
trace( "save-output=" + output );
fileStream.writeUTFBytes(output);
}
finally
{
try { fileStream.close(); } catch (error:*) { trace(error); }
}
}
public function load():void
{
var file:File = File.applicationStorageDirectory.resolvePath(CONFI G_FILE_NAME);
if( file.exists ) {
var fileStream:FileStream = new FileStream();
try
{
fileStream.open(file, FileMode.READ);
var config:XML = new XML(fileStream.readUTFBytes(fileStream.bytesAvaila ble));
if (config.hasOwnProperty('my_data'))
{
restore(config.my_data);
}
trace( "load-input=" + config.toString() );
}
finally
{
try { fileStream.close(); } catch(error:*) { trace(error); }
}
}
}