Actionscript 3 - checking for an internet connection - actionscript-3

I am using this code in my flash file
import air.net.URLMonitor;
import flash.net.URLRequest;
import flash.events.StatusEvent;
var monitor:URLMonitor;
function checkInternetConnection(e:Event = null):void
{
var url:URLRequest = new URLRequest("http://www.google.com");
url.method = "HEAD";
monitor = new URLMonitor(url);
monitor.pollInterval = 1000;
//
monitor.addEventListener(StatusEvent.STATUS, checkHTTP);
//
function checkHTTP(e:Event = null):void
{
if (monitor.available) {
navigateToURL(new URLRequest("flickr.html"),"_top");
} else {
gotoAndPlay(1);
}
}
monitor.start();
}
I am trying to get the flash to check for a connection and navigate to another page if not it will replay.
It doesnt seem to be working.
Am i missing anything?
I have add the library path to aircore.swc also.
Its meant to be a html page with flash rather than an AIR app
Cheers

(My reputation is too low to comment on Tianzhen Lin's answer directly ...)
I needed to make a few changes in order to get Tianzhen Lin's answer to work as expected:
Added:
urlRequest.useCache = false;
urlRequest.cacheResponse = false;
This addition was required because even when the connection was definitely lost, the check was still succeeding because the cache was being read from.
Changed:
if( textReceived.indexOf( _contentToCheck ) )
to:
if( !(textReceived.indexOf( _contentToCheck ) == -1) )
This change was required because while "" (an empty string) was always being found, it was being found at index '0' which was causing the original if() condition to always fail.
Added:
urlRequest.idleTimeout = 10*1000;
In the case where the network cable was physically disconnected from the router, the request could take a very long time to time-out (Honestly, I got tired of waiting after a couple of minutes.)
After making the above changes, I found Tianzhen's code worked perfectly: No matter how I went about disconnecting/reconnecting Wi-Fi (on both iOS and Android devices) the change in connection status was always detected.

I see two issues in your code. One is that while you have the logic to check internet connection, there is not any code calling the function, therefore the logic of redirection would not be called. Second is that using AIRcore.swc would be a bad idea as you have injected a dependency that might not work with or violate browser sandbox.
You may try the following approach which is tested and requires no AIR's SWC:
Step 1, include a new class ConnectionChecker as follow:
package
{
import flash.events.*;
import flash.net.*;
[Event(name="error", type="flash.events.Event")]
[Event(name="success", type="flash.events.Event")]
public class ConnectionChecker extends EventDispatcher
{
public static const EVENT_SUCCESS:String = "success";
public static const EVENT_ERROR:String = "error";
// Though google.com might be an idea, it is generally a better practice
// to use a url with known content, such as http://foo.com/bar/mytext.txt
// By doing so, known content can also be verified.
// This would make the checking more reliable as the wireless hotspot sign-in
// page would negatively intefere the result.
private var _urlToCheck:String = "http://www.google.com";
// empty string so it would always be postive
private var _contentToCheck:String = "";
public function ConnectionChecker()
{
super();
}
public function check():void
{
var urlRequest:URLRequest = new URLRequest(_urlToCheck);
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, loader_complete);
loader.addEventListener(IOErrorEvent.IO_ERROR, loader_error);
try
{
loader.load(urlRequest);
}
catch ( e:Error )
{
dispatchErrorEvent();
}
}
private function loader_complete(event:Event):void
{
var loader:URLLoader = URLLoader( event.target );
var textReceived:String = loader.data as String;
if ( textReceived )
{
if ( textReceived.indexOf( _contentToCheck ) )
{
dispatchSuccessEvent();
}
else
{
dispatchErrorEvent();
}
}
else
{
dispatchErrorEvent();
}
}
private function loader_error(event:IOErrorEvent):void
{
dispatchErrorEvent();
}
private function dispatchSuccessEvent():void
{
dispatchEvent( new Event( EVENT_SUCCESS ) );
}
private function dispatchErrorEvent():void
{
dispatchEvent( new Event( EVENT_ERROR ) );
}
}
}
Step 2, in your main application or anywhere that internet connection should be checked, use the following snippet:
var checker:ConnectionChecker = new ConnectionChecker();
checker.addEventListener(ConnectionChecker.EVENT_SUCCESS, checker_success);
checker.addEventListener(ConnectionChecker.EVENT_ERROR, checker_error);
checker.check();
private function checker_success(event:Event):void
{
// There is internet connection
}
private function checker_error(event:Event):void
{
// There is no internet connection
}

The air.net.URLMonitor is the AIR available class - so will not work outside of the AIR player.
But you could try to do your own as all this monitor class does is "ping" the url and check the response, so you could do similar try to load something from known source like google.com and if it completes wihtout error then it is OK otherwise you will get error.

Related

How to free memory after use of FileRerence?

See [Solution]
FileReference.load(); does not have a function to unload, just as there is new Loader ().unload();.
Must be a "BUG" from Flash or FileReference needs improvement, type in a new version add a function like this: FileReference.unload();
Or am I mistaken and exists a SOLUTION?
I tried to set "NULL" to a variable of type FileReference, but clearly this does not work for the Flash works with GC (garbage collector), but this is not the focus of the question.
The problem is that a lot of memory when loading multiple files with new FileReferenceList is necessary, but I can not free memory after the process.
How to free memory after use of FileRerence?
See my code:
Main.as
package {
import com.mainpackage.LoaderTestCase;
import flash.net.FileReferenceList;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.Event;
import flash.display.MovieClip;
public class Main extends MovieClip {
private var listFiles:Array;
private var allTypes:Array;
private var fileRef:FileReferenceList;
private var test:int;
public function Main()
{
test = 0;
listFiles = [];
allTypes = [];
fileRef = new FileReferenceList();
fileRef.addEventListener(Event.SELECT, select);
fileRef.browse(allTypes);
}
private function select(e:Event):void
{
listFiles = fileRef.fileList;
for(var i:uint=0, j:uint=listFiles.length; i<j; i++)
{
insert(i);
}
}
private function insert(c:int):void
{
var fire:LoaderTestCase = new LoaderTestCase(listFiles[c]);
fire.destroy(function():void
{
//Delete LoaderTestCase after timeout ???
fire = null;
test++;
if(test>=listFiles.length) {//Remove FileReference
fileRef.removeEventListener(Event.SELECT, select);
fileRef = null;
for(var i:uint=0, j:uint=listFiles.length; i<j; i++) {
listFiles[i] = null;
}
listFiles = null;
trace("Clear memory");
}
});
}
}
}
LoaderTestCase.as
package com.mainpackage
{
import flash.net.FileReference;
import flash.events.Event;
import flash.display.Loader;
public class LoaderTestCase
{
private var file:FileReference;
private var loader:Loader;
private var callback:Function;
public function LoaderTestCase(e:FileReference)
{
file = e;
trace("OPEN: " + file.name);
file.addEventListener(Event.COMPLETE, loadFile);
file.load();
e = null;
}
public function loadFile(e:Event):void
{
file.removeEventListener(Event.COMPLETE, loadFile);
trace("LOAD: " + file.name);
file = null;
e = null;
callback();
}
public function destroy(a:Function):void
{
callback = a;
}
}
}
Remove the event listeners before you null the listening object.
You could use weak references to let the listeners be removed when the object is Garbage Collected.
object.addEventListener( ......, ......., false, 0, true );
for example, in your LoadFile function:
...
LoadFile(file);
}
});
...
should be:
...
LoadFile(file);
}
}, false, 0, true );
...
Or you will have to remove them manually.
To do that you will need to move the event handlers into new named functions.
Also you will need an array for storing the references to listeners and listening objects, to be able to remove the listeners AFTER the listeners are not needed any more and BEFORE nulling the listening object.
PLEASE NOTE:
When you are testing it and watching the current memory usage, make sure to force the Garbage Collector when you feel the memory usage should have dropped by now, but it didn't.
GC kicks in when it wants and very not necessarily after something has been nulled on unloaded.
To be clear, I am only talking about forcing GC during the development/testing.
Even if you null every reference to an object, it won't be deleted immediately from the memory. You have to remove the event listeners aswell. Also, never use "unnamed" functions... it is harder to remove a listener when the event calls an unnamed function. So create a new function, and call that one. For example:
test.contentLoaderInfo.addEventListener(Event.COMPLETE, contentLoaderInfoComplete);
...
function contentLoaderInfoComplete(e:Event){
test.contentLoaderInfo.removeEventListener(Event.COMPLETE, contentLoaderInfoComplete);
test.unload();
test = null;
}
This will clean the memory.
I reached my goal, if I so did FileReferenceList.fileList[5] = null; (when the "sixth file" is not being used more) Flash memory immediately frees this specific FileReference.
In the others words:
This not work:
private var file:FileReference;
...
file = FileReferenceList.fileList[5];
...
file = null;
But this worked:
FileReferenceList.fileList[5] = null;
Worked on all Desktop/Plugins/PepperFlash.
See worked code:
package {
import flash.net.FileReferenceList;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
public class Main extends Sprite
{
private var listFiles:Array;
private var allTypes:Array;
private var fileRef:FileReferenceList;
private var tmpFile:FileReference;
private var i:uint=0;
private var j:uint=0;
private var timer:uint;
private var imageTypes:FileFilter;
private var enable:Boolean;
public function Main()
{
imageTypes = new FileFilter(
"Images (*.JPG;*.JPEG;*.JPE;)", "*.jpg; *.jpeg; *.jpe;"
);
listFiles = [];
allTypes = [imageTypes];
eventBrowse(true);
}
private function eventBrowse(a:Boolean):void
{
enable = a;
if(a===true) {
stage.addEventListener(MouseEvent.CLICK, browse);
fileRef = new FileReferenceList();
fileRef.addEventListener(Event.SELECT, select);
} else {
fileRef.removeEventListener(Event.SELECT, select);
fileRef = null;
stage.removeEventListener(MouseEvent.CLICK, browse);
}
}
private function browse(e:MouseEvent):void
{
if(enable===true) {
fileRef.browse(allTypes);
}
}
private function select(e:Event):void
{
listFiles = fileRef.fileList;
eventBrowse(false);
i=0;
j=listFiles.length;
if(j>0) {
loadNextFile();
}
}
private function loadNextFile():void
{
if(!(i<j)) {
listFiles = null;
trace("Free memory???");
trace("--------------");
trace("listFiles:"+ listFiles);
trace("allTypes:" + allTypes);
trace("fileRef:" + fileRef);
trace("tmpFile:" + tmpFile);
trace("i:" + i);
trace("j:" + j);
trace("timer:" + timer);
trace("--------------");
eventBrowse(true);
return;
}
tmpFile = listFiles[i];
trace("Initiate load:" + tmpFile.name);
tmpFile.addEventListener(Event.COMPLETE, loadedFile);
tmpFile.load();
}
private function loadedFile(f:Event):void
{
trace(listFiles);
trace("Finished load:" + tmpFile.name);
tmpFile.removeEventListener(Event.COMPLETE, loadedFile);
tmpFile = null;
listFiles[i] = null;
i++;
loadNextFile();
}
}
}
The issue is a combination of all the things noted above.
You do need to remove the event listener(s) manually. While its possible to use weak references its better if you make a habit of keeping track of the listeners you register and always unregister them properly. This way you can better avoid memory leaks(not quite a memory leak but has a similar effect) you didn't expect or weren't thinking about.
You are creating event listeners in a loop and re-using the same function to handle all of them. If you do this you must somehow get a reference to the original loader and remove the event listener from it. I have no idea how you tried to incorporate Zhafur's answer but if you re-used file reference for each new file that will be the reason its still not working. Perhaps you can update you example above with the code you currently have so we can critique further.
You should never force the gc(garbage collector), if you need to do this you have issues elsewhere you should solve instead as san.chez mentioned. Forcing the GC is a good way to see that you are creating too many objects too fast, if you see your memory usage go way down after forcing the GC you probably did this and should rewrite your code to be more efficient in its use of new.
Judging by the amount of memory you have consumed your either creating a ton of small files or a few extremely large ones, perhaps you can tell us more about that as well.

AS3 - Local P2P networking receiving only "undefined" data

I'm trying to make a simple P2P networking system to send messages to other Flash Players on your network.
However, when I send a message the receiving player doesn't receive a message but rather a undefined object.
I did allow Flash Player in my Virus Scanner (NOD 32) and my Windows Firewall by the way.
Here's my P2P class:
package com.snakybo.as3framework.network {
import flash.events.Event;
import flash.events.NetStatusEvent;
import flash.net.GroupSpecifier;
import flash.net.NetConnection;
import flash.net.NetGroup;
/** #author Kevin */
public class P2P extends NetConnection {
private var netCon:NetConnection;
private var netGroup:NetGroup;
private var handler:Function;
private var groupName:String;
public function P2P(groupName:String, handler:Function) {
this.groupName = groupName;
this.handler = handler;
netCon = new NetConnection();
netCon.addEventListener(NetStatusEvent.NET_STATUS, conHandler);
netCon.connect("rtmfp:");
}
/** Post a message */
public function post(txt:*):void {
var data:Object = new Object();
data["txt"] = txt;
data["id"] = new Date().time;
netGroup.post(data);
}
/** Handle connection event listener */
private function conHandler(e:NetStatusEvent):void {
if(e.info["code"] == "NetConnection.Connect.Success") {
setupGroup();
}
}
/** Connect to group */
private function setupGroup():void {
var groupSpec:GroupSpecifier = new GroupSpecifier(groupName);
groupSpec.postingEnabled = true;
groupSpec.ipMulticastMemberUpdatesEnabled = true;
groupSpec.addIPMulticastAddress("225.225.0.1:30000");
netGroup = new NetGroup(netCon, groupSpec.groupspecWithAuthorizations());
netGroup.addEventListener(NetStatusEvent.NET_STATUS, handler);
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
Connection seems to be working, since I can send messages and the other player does receive them.. well.. receive something.
Then from my Main.as I call this class like this:
private var p2p:P2P;
public function Main():void {
p2p = new P2P("snakybo", netHandler);
p2p.addEventListener(Event.COMPLETE, onConnected);
}
private function onConnected(e:Event):void {
function send(e:KeyboardEvent):void {
c.post("a");
trace("poseted");
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, send);
}
private function netHandler(e:NetStatusEvent):void {
switch(e.info["code"]) {
case "NetGroup.Posting.Notify":
trace("received: " + e.info["txt"]);
break;
}
}
Also, if I add:
case "NetGroup.Connection.Success":
trace("Connected to group");
break;
It never prints that. Not sure what's wrong with that.
Am I doing anything wrong here? Or did my PC somehow block Flash Player?
In your P2P class you have this...
netCon.connect("rtmfp:");
This tells your NetConnection to connect to a string ("rtmfp:") which isn't a server or valid connection type if you are trying to reach outside members of the rtmfp connection. It appears you are using this for an internal network so "rtmfp" will work locally.
What I do with NetConnection.connect() is I set up my rtmfp constant and a developer key constant (for cirrus server) right off the bat like this...
cons SERVER:String = "rtmfp:";
cons DEVKEY:String = "your developer key here";
then
function connect(): void {
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
nc.connect(SERVER + DEVKEY);
}
You can go to adobes website if you are using their rtmfp server to get a developer key, they are free and easy to get anyway. Once you are connected you will get a NetStatus event string of "NetConnection.Connect.Success" which your conHandler function is set up to receive. I use a Switch Case within mine to listen for the connect string and do something based off each string like this:
function netStatus(event: NetStatusEvent): void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
setupGroup();
break;
} }
Fire your setupGroup() function when you hear "NetConnection.Connect.Success". Then within your setupGroup() go ahead and set your
groupspec.serverChannelEnabled = true;
groupspec.routingEnabled = true;
groupspec.objectReplicationEnabled = true; // and I have
groupspec.peerToPeerDisabled = false;
Also, in your setupGroup you are firing "handler" instead of "conHandler" which is the name of your NetStatus event function handler. Probably just a typo. Setting the new NetGroup itself will fire 1 of 3 NetStatus events telling you the status of the new netgroup connection so you won't need to dispatch the event you are using unless you want to, up to you. You can handle those in your conHandler function as well.
I will typically have a trace statement setup to print out the NetStatusEvent so in your case that would be... trace(e.info.code) and you will be able to see the events as they happen and be able to troubleshoot problems much easier. Once you get this connection up you'll be able to handle the delivering of objects.
This should at least get you a created instance and the connection to others in the group. I have included a couple links I referenced here:
NetGroup
NetStatus
NetConnection
Try googling Tom Krcha, he is with adobe and has some good info on this as well.

Geolocation StatusEvent Never Fires

I am developing an AIR for iOS app and I have just this one issue left on my list of bugs to fix. Basically, when a certain window is opened, the user is able to use their current position to search. I am using the Geolocation class for this and it works fine, except for the fact that StatusEvent.STATUS is not firing. The user is prompted to give permission to use their current location, as it should, but when they choose, my StatusEvent handler is never called.
if ( Geolocation.isSupported ) {
var geo:Geolocation = new Geolocation();
geo.addEventListener( StatusEvent.STATUS, this.geolocationStatusHandler );
this.geolocationStatusHandler();
}
protected function geolocationStatusHandler( e:StatusEvent = null ):void{
var geo:Geolocation = new Geolocation();
this.gpsButton.enabled = !geo.muted;
}
The only thing I can think of is that the alert window (which freezes app execution) is opened with new Geolocation(), before I add the event listener. But if that were the case, calling the handler manually wouldn't occur until after the user closed the Alert (it happens at the same time, roughly. A breakpoint there stops the app while the alert is open)
Is there a solution for this? I could always move the prompt to the very beginning of the app, but I personally prefer not being prompted until it is needed.
Details:
ActionScript Mobile project built with AIR 3.6 SDK
Tested on iPad 2, 3, and Mini, all running iOS 6.1.3
Tested in both release and debug modes
Listen for the GeolocationEvent.UPDATE event.
Also, it appears you're manually calling the handler immediately after the listener; then your handler is instantiating a new Geolocation instead of getting GeolocationEvent latitude and longitude.
Example implementation using Google Geocoding API from XpenseIt tutorial:
package
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.GeolocationEvent;
import flash.sensors.Geolocation;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
[Event(name="locationUpdate", type="flash.events.Event")]
public class GeolocationUtil extends EventDispatcher
{
protected var geo:Geolocation;
public var updateCount:int;
protected var service:HTTPService = new HTTPService();
public var location:String;
public var longitude:Number;
public var latitude:Number;
public function GeolocationUtil()
{
service.url = "https://maps.googleapis.com/maps/api/geocode/xml";
}
public function geoCodeAddress(address: String):AsyncToken
{
return service.send({address: address, sensor: Geolocation.isSupported});
}
public function getLocation():void
{
if (Geolocation.isSupported)
{
geo = new Geolocation();
geo.setRequestedUpdateInterval(500);
updateCount = 0;
geo.addEventListener(GeolocationEvent.UPDATE, locationUpdateHandler);
}
}
protected function locationUpdateHandler(event:GeolocationEvent):void
{
// Throw away the first location event because it's almost always the last known location, not current location
updateCount++;
if (updateCount == 1) return;
if (event.horizontalAccuracy <= 150)
{
trace("lat:" + event.latitude + " long:" + event.longitude + " horizontalAccuracy:" + event.horizontalAccuracy);
geo.removeEventListener(GeolocationEvent.UPDATE, locationUpdateHandler);
geo = null;
}
longitude = event.longitude;
latitude = event.latitude;
var token:AsyncToken = service.send({latlng: latitude+","+longitude, sensor: Geolocation.isSupported});
token.addResponder(new AsyncResponder(
function(event:ResultEvent, token:AsyncToken):void
{
// Map the location to city and state from the response address component
location = event.result.GeocodeResponse.result[0].address_component[3].long_name + ', '+ event.result.GeocodeResponse.result[0].address_component[5].long_name;
dispatchEvent(new Event("locationUpdate"));
},
function (event:FaultEvent, token:AsyncToken):void
{
// fail silently
trace("Reverse geocoding error: " + event.fault.faultString);
}));
}
}
}

flash as3 serial port

Hey trying to bring data in through the serial port but i get this error.
1037: Packages cannot be nested.
I then need to take these values and use 1 to control video playback and the other to control the audio volume
package
{
import flash.display.Sprite;
import flash.net.XMLSocket;
import flash.events.DataEvent;
public class receiveData extends Sprite
{
public static const PORT:Number = 5331;
public static const COMMA:String = ",";
public static const LOCALHOST:String = "127.0.0.1";
private var socket:XMLSocket = null;
public function receiveData()
{
super();
init();
}
private function init():void
{
socket = new XMLSocket();
socket.addEventListener( DataEvent.DATA, doSocketData );
socket.connect( LOCALHOST, PORT );
}
protected function doSocketData( event:DataEvent ):void
{
var parts:Array = null;
var sensorone:Number = 0;
var sensortwo:Number = 0;
var values:String = event.data.toString();
parts = values.split( COMMA );
trace( parts[0]);
trace( parts[1]);
sensorone = new Number( parts[0] );
sensortwo = new Number( parts[1] );
}
}
}
So basically you need to put that code in a separate AS3 file and set that as the document class or as the class file for a MovieClip you make in Flash. Alternatively you could use a different IDE like FlashBuilder or FlashDevelop or FDT and avoid the Flash IDE (which as a programmer primarily I feel muddles things up quite a bit).
http://www.actionscript.org/forums/showthread.php3?t=136364 (haha SO won't let me LMGTFY)
Looks like you're on the right track though if you're using tinkerproxy or something of the sort to forward the data (have fun I gotta get myself back into that, check out links in th description of my vid http://www.youtube.com/watch?v=71eFWknHKEM&list=UUSz-eugjE1d6yki6ZT51CKg&index=17&feature=plcp :)

Read/write as3 zip using fzip

I'm creating a custom file type in AIR, which is a zip file under a different extension. I've been trying a few libs out, and settled on Fzip. This is to house my apps project files.
The tests seem to run OK, apart from occasionally getting 'Unknown record signature' Error.
I'm wondering if I'm missing something, and perhaps someone can shed some light. First time I've attempted something like this.
It seems to occur randomly, I have a basic app which allows you to add new files at runtime. Contents display in a list and upon select you view the text content.
From time to time when adding a new file, saving, then reopening I get this unknown record error. The main functions which could be the cause
private function openComplete( event:Event ):void {
_zipFile.loadBytes( _file.data );
dispatch( new ZipServiceEvent( ZipServiceEvent.CONTENTS_CHANGE ) );
}
public function saveFile( event:Event=null ):void {
if( _file.isDirectory ) {
browseForSave();
return void;
}
if ( _file.extension != _ext )
_file = new File( _file.nativePath + _ext );
var stream:FileStream = new FileStream();
stream.open( _file, FileMode.WRITE );
_zipFile.serialize( stream );
stream.close();
}
public function getFile( name:String ):FZipFile {
return _zipFile.getFileByName( name );
}
public function addFile( name:String, contents:ByteArray ):void {
_zipFile.addFile( name, contents );
}
private function saveFileHandler( event:Event ):void {
var contents:ByteArray = new ByteArray();
contents.writeMultiByte( view.filecontents.text, 'utf-8' );
model.addFile( view.filename.text, contents );
}
I would need to test you class to look for errors… I wont have time to check it but in the meanwhile I´ll post an Util class I created for this purpose. It´s not very extensive, it was just for a small project but it may help you…
package com.models
{
import com.events.AppEvent;
import deng.fzip.FZip;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.utils.ByteArray;
public class ZIPEncoder extends EventDispatcher
{
private var _zip:FZip;
private var _compressedBytes:ByteArray = new ByteArray();
public function ZIPEncoder(target:IEventDispatcher=null)
{
super(target);
}
public function newZip(name:String = ""):void
{
if(_zip) _zip = null;
_zip = new FZip();
_zip.addEventListener(Event.COMPLETE, onZipComplete);
}
public function newEntry(name:String, bytes:ByteArray):void
{
if(_zip == null)
{
throw(new Error("No zipOutput initialized. Call newZip() to initialize a new ZipOutput object before creating entry instances"));
return;
}
_zip.addFile(name, bytes);
}
public function compress():void
{
_zip.serialize(_compressedBytes, false);
dispatchEvent(new AppEvent(AppEvent.ZIP_ENCODED, _compressedBytes));
}
private function onZipComplete(event:Event):void
{
dispatchEvent(new AppEvent(AppEvent.ZIP_ENCODED, _compressedBytes));
}
//public function get zip():ZipOutput { return _zip; }
}
}
hope it helps…