With only that code, it must be either page, or page.Text, is null.
Going by the names, I would guess page is a Flash library object you create with AS? If so, I would guess a previous error is firing before it is created and being swollowed by the player (can happen if the debugger has not attached yet, or problems with loading shared librarys). 'stage' not being set for new display object until it's added to the display list is common.
EDIT: It's a bug in the component: draw()
always uses the highScoresModuleText
property on page: which is only set when the page is a HighScoresTextPage
, and not any of the other pages, eg: HighScoresTablePage
, which showHighsSores()
sets it to. This works in Flash presumably because the object is on the stage, or at least gets created before showHighScores()
is called, so draw()
gets called first, and since the component does not invalidate, is not called after.
The correct method in this case is to have show*()
just set some properties, then invalidate()
to have draw()
figure it out later, but a quick fix is to just add 'if (page.highScoresModuleText)
' around the offending lines in draw()
. An even quicker fix is to create and addChild()
the component early (like startup), and call showHighScores()
much later.
This works for me:
package
{
import flash.display.Sprite;
import com.novelgames.flashgames.highscores.HighScores;
import flash.events.MouseEvent;
public class As3_scratch extends Sprite
{
private var highscore : HighScores;
public function As3_scratch()
{
highscore = new HighScores();
addChild(highscore);
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(event : MouseEvent) : void
{
highscore.showEnterHighScore(50);
}
}
}