将推送的Stack对象弹出内容到textarea

时间:2011-03-02 21:40:09

标签: flex actionscript-3 stack

我正在寻找一个包含String和Integer上下文的对象,它已经推送到堆栈并将这些特定内容弹出到用户可以看到的显示中。显示屏由两个textareas和一个标签组成。

我无法弄清楚如何访问对象的各个部分来显示它们。

这是我的Stack.as类:

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;
    }
  }
}

这就是我如何弹出它:

...

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;

...

以下是我在堆栈上推送它的方式:

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;
            }

任何帮助或建议都会很棒,非常感谢。谢谢!

REVISION

推送:

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;
            }

要弹出:

if(shuffle == 0)
            {

                var r:Object = stackArray.pop();
                if(r != null)
                {
                stext1.text = r.cSide1;
                stext2.text = r.cSide2;
                cardNumberLabel.text = r.id;
                }

1 个答案:

答案 0 :(得分:1)

看起来这部分是错误的

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; <<<<<<<<<<<<<<<why just return Object, why not return first.data and remove first.data from the list.
    }

如果可以使用数组,它看起来像链接列表实现它可能通过使用数组来节省一些麻烦,并且如果你想要传统的Stack行为,使用push和shift它就好像。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html

希望有所帮助,

肖恩