Re: [Flashcoders] How to serialize key events?

2006-05-16 Thread Ron Wheeler

What kind of object do you need to save?

The nice thing about this approach is that you can create any object 
that you need and put it in the queue.
If you only need a list of buttons pressed, you can have a very simple 
object. If you need to include internally generated events, you may need 
an object with more properties.
You do not even have store the same type of object each time as long as 
you can figure out what object is being returned when you ask for the 
next one.


Ron
black59mga wrote:
Ron, 
Thanks very much for your response. You asked  What is wrong with this?. Probably nothing.. Just lack of experience on my part. The class is now actionscript. I'm trying to figure out what's the right kind of Object to pass to the insert(obj:Object) method. Thoughts?


Thanks!

The class:

class Mailbox {
  private var  numMessages:Number = 0;
  private var mailbox:Array = new Array();

  public function insert(obj:Object):Void {
  trace(Mailbox:: Insert)
mailbox.addElement(obj);
numMessages++;
   // notify();
  }

  public function remove() {
while (numMessages == 0) {
  try {
//wait();
  } catch (e:Error) {
  }
}

var obj:Object = mailbox.firstElement();
mailbox.removeElementAt(0);
numMessages--;
return obj;
  }

  public function numobj():Number {
return numMessages;
  }

  public function flush():Array {
var array:Array = null;
if (numMessages  0)
  array = new Array();
while (numMessages  0) {
  var obj:Object = mailbox.firstElement();
  array.addElement(obj);
  mailbox.removeElementAt(0);
  numMessages--;
}
return array;
  }
}

Ron Wheeler [EMAIL PROTECTED] wrote:
The code is pretty simple. Have you tried to code and test it under 
ActionScript?
It looks like you add objects  to a list and take the first one off the 
list. It provides a function to find out if there are any objects in the 
queue. What is wrong with this?


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___

Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


  

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] How to serialize key events?

2006-05-15 Thread Ron Wheeler
You might try reading the Java class documents to see what is special 
about Vectors as opposed to Arrays in Actionscript.


The code is pretty simple. Have you tried to code and test it under 
ActionScript?
It looks like you add objects  to a list and take the first one off the 
list. It provides a function to find out if there are any objects in the 
queue.

What is wrong with this?

Ron

black59mga wrote:

I posted this a few day ago on Newbie. No response so posting here

Does anyone know a simple way to serialize key events?

A Java prog. friend suggested using a Mailbox class to serialize the key 
input and provided a class (below) but I don't really understand java Vectors. Ideas?

thanks very much!




import java.util.*;

public class Mailbox {
  private intnumMessages = 0;
  private Vector mailbox = new Vector();

  public synchronized void insert(Object obj) {
mailbox.addElement(obj);
numMessages++;
notify();
  }

  public synchronized Object remove() {
while (numMessages == 0) {
  try {
wait();
  } catch (Exception e) {
  }
}

Object obj = mailbox.firstElement();
mailbox.removeElementAt(0);
numMessages--;
return obj;
  }

  public synchronized int numobj() {
return numMessages;
  }

  public synchronized Vector flush() {
Vector vector = null;
if (numMessages  0)
  vector = new Vector();
while (numMessages  0) {
  Object obj = mailbox.firstElement();
  vector.addElement(obj);
  mailbox.removeElementAt(0);
  numMessages--;
}
return vector;
  }
}

-
Yahoo! Mail goes everywhere you do.  Get it on your phone.
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


  

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] How to serialize key events?

2006-05-15 Thread black59mga
Ron, 
Thanks very much for your response. You asked  What is wrong with this?. 
Probably nothing.. Just lack of experience on my part. The class is now 
actionscript. I'm trying to figure out what's the right kind of Object to pass 
to the insert(obj:Object) method. Thoughts?

Thanks!

The class:

class Mailbox {
  private var  numMessages:Number = 0;
  private var mailbox:Array = new Array();

  public function insert(obj:Object):Void {
  trace(Mailbox:: Insert)
mailbox.addElement(obj);
numMessages++;
   // notify();
  }

  public function remove() {
while (numMessages == 0) {
  try {
//wait();
  } catch (e:Error) {
  }
}

var obj:Object = mailbox.firstElement();
mailbox.removeElementAt(0);
numMessages--;
return obj;
  }

  public function numobj():Number {
return numMessages;
  }

  public function flush():Array {
var array:Array = null;
if (numMessages  0)
  array = new Array();
while (numMessages  0) {
  var obj:Object = mailbox.firstElement();
  array.addElement(obj);
  mailbox.removeElementAt(0);
  numMessages--;
}
return array;
  }
}

Ron Wheeler [EMAIL PROTECTED] wrote:
The code is pretty simple. Have you tried to code and test it under 
ActionScript?
It looks like you add objects  to a list and take the first one off the 
list. It provides a function to find out if there are any objects in the 
queue. What is wrong with this?

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] How to serialize key events?

2006-05-15 Thread Scott Hyndman
The array class does not have addElement or removeElement methods.

Read the docs for push and splice.

Scott

-Original Message-
From:   [EMAIL PROTECTED] on behalf of black59mga
Sent:   Mon 5/15/2006 6:16 PM
To: Flashcoders mailing list
Cc: 
Subject:Re: [Flashcoders] How to serialize key events?

Ron, 
Thanks very much for your response. You asked  What is wrong with this?. 
Probably nothing.. Just lack of experience on my part. The class is now 
actionscript. I'm trying to figure out what's the right kind of Object to pass 
to the insert(obj:Object) method. Thoughts?

Thanks!

The class:

class Mailbox {
  private var  numMessages:Number = 0;
  private var mailbox:Array = new Array();

  public function insert(obj:Object):Void {
  trace(Mailbox:: Insert)
mailbox.addElement(obj);
numMessages++;
   // notify();
  }

  public function remove() {
while (numMessages == 0) {
  try {
//wait();
  } catch (e:Error) {
  }
}

var obj:Object = mailbox.firstElement();
mailbox.removeElementAt(0);
numMessages--;
return obj;
  }

  public function numobj():Number {
return numMessages;
  }

  public function flush():Array {
var array:Array = null;
if (numMessages  0)
  array = new Array();
while (numMessages  0) {
  var obj:Object = mailbox.firstElement();
  array.addElement(obj);
  mailbox.removeElementAt(0);
  numMessages--;
}
return array;
  }
}

Ron Wheeler [EMAIL PROTECTED] wrote:
The code is pretty simple. Have you tried to code and test it under 
ActionScript?
It looks like you add objects  to a list and take the first one off the 
list. It provides a function to find out if there are any objects in the 
queue. What is wrong with this?

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

RE: [Flashcoders] How to serialize key events?

2006-05-15 Thread black59mga
oops! you are correct. Thanks


Scott Hyndman [EMAIL PROTECTED] wrote: The array class does not have 
addElement or removeElement methods.

Read the docs for push and splice.

Scott



-
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com