0

我正在尝试编写纸牌游戏,但我被一个投注系统困住了......这是我的 .fla 文件脚本:

set var pot:int = 0;
set var money:int = 100;
set var smoney:String = money + "$";

addChild(cash);
cash.text = String(smoney);

这是我的类文件的脚本:

package classes
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class Chip1 extends MovieClip
    {

        public static var pot:int;
        public static var money:int;
        public static var smoney;

        public function Chip1()
        {
            x = 8.35;
            y = 948.60;

            addEventListener(MouseEvent.MOUSE_DOWN,chip1take);
            addEventListener(MouseEvent.MOUSE_UP,chip1bet);

        }
        function chip1take(event:MouseEvent):void
        {

            startDrag();
            scaleX = 1.1;
            scaleY = 1.1;
        }


        function chip1bet(event:MouseEvent):void
        {

            stopDrag();
            scaleX = 0.5;
            scaleY = 0.5;

            trace(dropTarget.name);

            if (dropTarget.name == "instance2")
            {
                pot +=  1;
                money -=  1;
                smoney = money + "$";

                addChild(cash);
                cash.text = String(smoney);

                removeEventListener(MouseEvent.MOUSE_DOWN,chip1take);
                removeEventListener(MouseEvent.MOUSE_UP,chip1bet);

            }
            else
            {

                scaleX = 1;
                scaleY = 1;
                x = 8.35;
                y = 948.60;
            }



            trace(pot);
  }
 }
}

问题是我找不到从我的类文件中编辑动态文本字段“现金”的方法,它只是给我一个错误 1120,因为我没有将它链接到我的 .fla 文件。那么我该怎么做呢?

我是新手,还在学习。

4

1 回答 1

0

将这两行添加到您的导入中:

import flash.display.DisplayObjectContainer;
import flash.text.TextField;

之后,您将能够通过TextField以下方式获得现金:

TextField(DisplayObjectContainer(stage.getChildAt(0)).getChildByName("cash")).text=String(smoney);
于 2013-05-25T09:00:16.017 回答