我正在尝试对纸牌游戏进行编码,但我仍然坚持使用投注系统...... 这是我的.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);
}
}
}
问题是我找不到从我的类文件中编辑Dynamic Textfield“cash”的方法,它只是给我一个错误1120因为我没有将它链接到我的.fla文件。 那我怎么能这样做呢?
我是新人,仍然在学习它。
答案 0 :(得分:0)
将这两行添加到您的导入中:
import flash.display.DisplayObjectContainer;
import flash.text.TextField;
之后,您将能够以这种方式获得现金TextField
:
TextField(DisplayObjectContainer(stage.getChildAt(0)).getChildByName("cash")).text=String(smoney);