ejansson
09-27-2008, 04:42 PM
I'm trying to put an existing Flash gameinto Flex. The Flash program is entirely AS except for the initial frame where I load the movie clip. Just trying to move it into Flex.
Here's an illustration of my problem, which involves Sprites and Controls. Why does the button not show up in this sample app:
Flex MXML file:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.containers.Canvas;
import Game;
protected function init():void
{
var game:Game = new Game();
var u:UIComponent = new UIComponent();
u.addChild(game); // can't add sprite directly or we get an error
holder.addChild(u);
}
]]>
</mx:Script>
<mx:Canvas id="holder" width="100%" height="100%" creationComplete="init()"/>
</mx:Application>
AS Class file:
package
{
import flash.display.Sprite;
import mx.controls.Button;
public class Game extends Sprite
{
public function Game()
{
var b = new Button();
b.label = "My Button";
b.width = 100;
b.height = 35;
addChild(b); // does not work: no button shows up
}
}
}
Could not be simpler, but doesn't work.
I've been banging my head against this problem for 2 days. Please help me before my brains liquefy.
EJ
Here's an illustration of my problem, which involves Sprites and Controls. Why does the button not show up in this sample app:
Flex MXML file:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.containers.Canvas;
import Game;
protected function init():void
{
var game:Game = new Game();
var u:UIComponent = new UIComponent();
u.addChild(game); // can't add sprite directly or we get an error
holder.addChild(u);
}
]]>
</mx:Script>
<mx:Canvas id="holder" width="100%" height="100%" creationComplete="init()"/>
</mx:Application>
AS Class file:
package
{
import flash.display.Sprite;
import mx.controls.Button;
public class Game extends Sprite
{
public function Game()
{
var b = new Button();
b.label = "My Button";
b.width = 100;
b.height = 35;
addChild(b); // does not work: no button shows up
}
}
}
Could not be simpler, but doesn't work.
I've been banging my head against this problem for 2 days. Please help me before my brains liquefy.
EJ