功能X1根本不运行 - 没有跟踪结果,程序如此基本
Board.as被称为 - 我检查了。
简单的精灵显示不起作用。
Main.as
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.*;
import flash.text.TextField;
import flash.ui.Keyboard;
import Start;
import Board;
/**
* ...
* @author Michael
*/
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init():void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var Board1:Sprite = new Board();
stage.addChild(Board1);
Board1.visible = true;
var Start1:Sprite = new Start();
Start1.x = 32;
Start1.y = 32;
addChild (Start1);
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void{
if (e.keyCode ==Keyboard.SPACE)
{
removeChild(Start1);
Start1 = null;
}
}
}
Board.as
package
{
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.display.Sprite;
/**
* ...
* @author Michael
*/
public class Board extends Sprite
{
[Embed(source="../lib/Board.jpg")]
private var BoardClass :Class
public function X1():void
{
var boardclass:Bitmap = new BoardClass () as Bitmap;
trace("Project is running fine!");
this.addChild(boardclass);
}
}
}
答案 0 :(得分:1)
您没有调用函数X1()。将您创建Board的Main.as类中的代码部分更改为:
var Board1:Sprite = new Board();
Board1.X1();
stage.addChild(Board1);
您的代码的其他一些提示:
1)您不需要 Board1.visible = true;
,默认情况下可见
2)将Board1的名称更改为board1或仅更改板卡。这是用第一个大写字母调用类的标准。
修改强>
如果希望在创建对象时运行X1(),请在Board.as的构造函数中调用此函数。构造函数是在创建对象时运行的函数。对于Board.as,它将是这样的:
public function Board():void
{
X1(); // this function will be called when you create a new Board object
}