나는 게임 중입니다. 나는 플래시의 공정 줄을 설계하고 내가 무대에 var에 할당하고 기본 클래스 (main_c.as)에서 3. AS에 연결 한 :addChild가 예외를 throw합니다.
package {
import flash.display.MovieClip;
import flash.display.Stage;
public class main_c extends MovieClip {
static public var stageRef:Stage;
public var s:start_b;
public var bar:timer_bar;
public function main_c()
{
// constructor code
stageRef = stage;
s = new start_b();
addChild(s);
s.x = 260;
s.y = 225;
}
}
}
다음에있는 start_b 클래스가 버튼을 만들고 클릭하여 세 번째 클래스 (game.as)의 생성자를 시작합니다. 여기 start_b의 코드는 다음과 같습니다
package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
public class start_b extends SimpleButton {
public var g:game;
public function start_b()
{
// constructor code
this.addEventListener(MouseEvent.CLICK, start_g);
}
public function start_g(e:MouseEvent):void
{
g = new game();
this.removeEventListener(MouseEvent.CLICK, start_g);
this.visible = false;
}
}
그리고
지난 시간 나는 무대를 기준으로 상태 표시 줄을하면 addChild 싶지만 실행할 때 오류 얻을에서 - 여기TypeError: Error #1009: Cannot access a property or method of a null object reference. at game() at start_b/start_g()
을 당신이 나를 도울 수 있다면
package{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import main_c;
public class game extends MovieClip {
public var points:Number;
public var ptw:Number;
public var time:Timer;
public var bar:timer_bar = new timer_bar();
public var cnt:main_c;
public function game()
{
//restartirane na igrata (nulirane)
main_c.stageRef.addChild(bar);
points = 0;
time = new Timer(50);
time.addEventListener(TimerEvent.TIMER, flow);
time.start();
trace("d");
}
public function flow(t:TimerEvent):void
{
//code
//bar.y++;
}
public function addPoints():void
{
//function code here
}
public function removePoints():void
{
//function code here
}
public function checkTime():void
{
//function code here
}
public function end():void
{
//function code here
}
}
}
나는 감사하고 좋은 하루 :-) 매우 기쁠 것 : 세 번째 클래스의 코드 (game.as)입니다! 당신의 무대가 준비 경우
다른 사람이 솔루션을 작성해 주시면 감사하겠습니다. – Mariyan
좋은 답변이 있지만 이미 좋은 코딩 방법에 대한 메모가 몇 개 있습니다. 1) 클래스 이름은 대문자로하고 UpperCamelCase를 사용해야합니다 표준 플래시 라이브러리 클래스의 이름은 ex : MovieClip입니다. 그러므로'timer_bar' 클래스의 이름은'TimerBar'이어야하고'main_c' 클래스의 이름은'MainC' 등이되어야합니다. 2) 일반적으로 단일 문자보다 사람이 읽을 수있는 이름을 사용하는 것이 바람직합니다 . 's = new start_b();''startBtn = new StartButton();'으로 훨씬 더 읽기 쉽습니다.어쨌든, 그냥 몇 가지 포인터 :) – Ian