I’m looking to take an object that contains String and Integer context and that has pushed upon a Stack and pop those specific contents into a display that the user can see. The display consists of two textareas and a label.
I can’t figure out how to access the individual parts of the Object to display them though..
Here’s my Stack.as class:
Stack.as
package
{
// credit for this class: *@author Michael Avila
import Node;
public class Stack
{
private var first:Node;
public function isEmpty()
{
return first == null;
}
public function push(data:Object)
{
var oldFirst : Node = first;
first = new Node ();
first.data = data;
trace(first.data.toString());
first.next = oldFirst;
}
public function pop():Object
{
if (isEmpty())
{
trace ("Error: \n\t Objects of type Stack must contain data before you attempt to pop");
return true;
}
var data = first.data;
return Object;
}
}
}
And here’s how i’m popping it:
…
private function nextMoveLPart(event:EffectEvent):void // open up connection get
{
if(shuffle == 0)
{
var r:Object = s.pop();
trace(r);
stext1.text = r.cSide1;
trace(r.cSide1);
stext2.text = r.cSide2;
cardNumberLabel.text = r.id;
…
Here’s how I’m pushing it on stack:
if(i<=numResults-1)
{
var row:Object = result.data[i];
s.push(row);
stext1.text = row.cSide1;
stext2.text = row.cSide2;
cardNumberLabel.text = row.id;
}
Any help or advice would be awesome and much appreciated. Thank you!
REVISION
To Push:
public var stackArray:Array = new Array();
…
if(i<=numResults-1)
{
var row:Object = result.data[i];
stackArray.push(row);
stext1.text = row.cSide1;
stext2.text = row.cSide2;
cardNumberLabel.text = row.id;
}
To Pop:
if(shuffle == 0)
{
var r:Object = stackArray.pop();
if(r != null)
{
stext1.text = r.cSide1;
stext2.text = r.cSide2;
cardNumberLabel.text = r.id;
}
Looks like this part is wrong
Looks like a linked list implementation if an array could be used it’ll probably save some headaches by using an Array and using push and shift it looks like if you want a traditional Stack behavior.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html
Hope that helps,
Shaun