that1guy
11-17-2009, 01:46 AM
I have a project I used to compile fine with flash, now I'm trying to compile it with flex. I have a fla full of assets, and some as files. Some of the as files are linked to assets, such as StartScreen.as which extends Sprite and is linked to a library item I made in the gui.
Basically, I got all this working. I added the necessary source paths to flex, and compiled a swc with flash, and added the path to the swc to flex. I get no compiler errors. However, I get runtime errors, because for example startScreen.playButton is null. My StartScreen class is like this:
package
{
import flash.display.Sprite;
import flash.display.SimpleButton
import flash.events.MouseEvent;
public class StartScreen extends Sprite
{
public var playButton:SimpleButton;
protected var playCallback:Function;
public function StartScreen(playCallback:Function)
{
this.playCallback = playCallback;
playButton.addEventListener(MouseEvent.CLICK, playClickListener, false, 0, true);
}
protected function playClickListener(event:MouseEvent):void
{
playCallback();
}
}
}
And it's linked in the fla to a library item. However, after I compile in flex and try to run, I get a null reference error on the line I try to add the event listener, because playButton is null. How can I fix this?
When I compile with flash, the button I added in the gui and named "playButton" is automatically assigned to the member I called "playButton" in the as file. Is this not the case with flex?
Basically, I got all this working. I added the necessary source paths to flex, and compiled a swc with flash, and added the path to the swc to flex. I get no compiler errors. However, I get runtime errors, because for example startScreen.playButton is null. My StartScreen class is like this:
package
{
import flash.display.Sprite;
import flash.display.SimpleButton
import flash.events.MouseEvent;
public class StartScreen extends Sprite
{
public var playButton:SimpleButton;
protected var playCallback:Function;
public function StartScreen(playCallback:Function)
{
this.playCallback = playCallback;
playButton.addEventListener(MouseEvent.CLICK, playClickListener, false, 0, true);
}
protected function playClickListener(event:MouseEvent):void
{
playCallback();
}
}
}
And it's linked in the fla to a library item. However, after I compile in flex and try to run, I get a null reference error on the line I try to add the event listener, because playButton is null. How can I fix this?
When I compile with flash, the button I added in the gui and named "playButton" is automatically assigned to the member I called "playButton" in the as file. Is this not the case with flex?