4

This is what I do: In the 'Local Storage' dialog I set the pointer to 'None' to allow 0 kB. Then I run my code. I get the 'Local Storage' dialog with an [Allow] and [Deny] button. I click [Deny]

The output I get is

2. we are here now
3. adding a handler to the SharedObject

NOTE: The onFlushStatus event handler is NOT called.

I repeat the above stuff, but now click [Allow]. The output I get is the same:

2. we are here now
3. adding a handler to the SharedObject

NOTE: The onFlushStatus event handler is NOT called.

I was using the code from here Flex: How to detect if user has blocked shared object from writing

Whatever I try (and I tried much), the event handler gets never called on a [Allow] or [Deny] button click. But I want to know which button the user clicked.

var so: SharedObject = null;
var flushStatus: String = null;

so = SharedObject.getLocal('mySpace');
try {
  flushStatus = so.flush();
} catch (error: Error) {
  trace('1. could not write SharedObject to disk');
}           
trace('2. we are here now');
if (flushStatus == flash.net.SharedObjectFlushStatus.PENDING) {
  trace('3. adding a handler to the SharedObject');
  so.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
} 

public function onFlushStatus(event: NetStatusEvent): void
{
  trace('4. in event handler');
}      

As suggested I changed my code and added the event listener before calling flush(). Then I run my tests again. Unfortunately my onFlushStatus() is not called.

var so: SharedObject = null;
var flushStatus: String = null;

so = SharedObject.getLocal('mySpace');
trace('0. adding a handler to the SharedObject');
so.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus);
flushStatus = so.flush();
trace('2. we are here now');

public function onFlushStatus(event: NetStatusEvent): void
{
  trace('4. in event handler');
}      

The output I get for [Deny]

0. adding a handler to the SharedObject
2. we are here now

The output I get for [Allow]

0. adding a handler to the SharedObject
2. we are here now

The onFlushStatus() is not called.

Community
  • 1
  • 1
user2186259
  • 43
  • 1
  • 5

1 Answers1

0

From this link it appears that so.flush is returning a String with the result of the flush() command. Rather than looking for an event to be fired you should look at the value of the return. If it's a pending then add your event listener and check success/fail.

A good example: here

Community
  • 1
  • 1
ethrbunny
  • 10,379
  • 9
  • 69
  • 131