|
-
AS3 and flex components
(reposting this from the AS3 page, sorry if you're seeing twice, but this topic is in limbo )
I develop my AS3 projects in Flex Builder, which has been magic so far... but now I have a need for components.
There are two obvious paths here:
a) Use the Flash 9 component set (sounds like it works, but takes a bunch of hackwork, and its a small set really)
b) Use the Flex framework components. (I'd like to be able to use these, but am having trouble.)
Does anyone have suggestions regarding this choice?
I am currently trying to use the Flex framework, and have gone through a lot of work (and the entire internet) trying to figure it out. From what I've gathered, this is the way to do it:
Create a new FLEX project, with 1 mxml file:
Code:
<!-- @mxmlc -default-size 400 300 -incremental=false -->
<Main xmlns="*"/>
This file runs my Main.as file (which extends Application):
Code:
package {
import flash.display.*
import flash.text.*
import flash.events.*
import mx.core.*;
import mx.controls.*;
import mx.events.*
import mx.skins.halo.*;
public class Main extends Application
{
public function Main()
{
//initialize flex
super();
this.layout = "vertical";
this.setStyle("borderSkin",mx.skins.halo.HaloBorder);
this.addEventListener(FlexEvent.APPLICATION_COMPLETE, init);
}
private function init(eventObj:FlexEvent):void
{
trace("init()");
var clip:Sprite = new Sprite();
clip.x = 100;
clip.y = 50;
clip.graphics.beginFill(0x00aa00, .7);
clip.graphics.drawRect(0, 0, 300, 200);
addChild(clip);
}
}
}
Now I am under the impression that all of the above would work, except I get one error. addChild(clip) is not able to run because it is trying to add a sprite to the stage, and Flex will only accept Flex display objects.
Can anyone advise?
-
Senior Member
Please do not double post.
- The right of the People to create Flash movies shall not be infringed. -
-
How to fix...
AxiomFlash,
Instead of attaching the Sprite directly to the application you need to create an UIComponent attach the sprite to it and then attach the new UIComponent to the application. I've posted the solution here with a more in depth explanation:
http://tdotblog.info/?q=node/10
Basically, the Sprite class does not have all the method, events, and properties the application requires of its components. Thus you have to attach the sprite to a UIComponent first.
Hope this helps...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|