Mike Chambers

code = joy

Using Flex Components in ActionScript Projects

with 16 comments

A lot of people have had questions about whether you can use the Flex 2 Framework classes / controls (everything in mx.*) within an ActionScript 3 project without using any MXML.

You can definitely do this, and we have posted some info on the labs wiki that shows how (written by Gordon Smith).

You can view the info here.

You can download Flex Builder 2 and ActionScript from labs.macromedia.com.

Written by mikechambers

November 29th, 2005 at 1:14 pm

Posted in General

16 Responses to 'Using Flex Components in ActionScript Projects'

Subscribe to comments with RSS

  1. This is great mike… was just aksing round about this yesterday. Thanks a lot.

    JimmyH

    29 Nov 05 at 1:19 pm

  2. i can`t get it to work ;-(
    Are you sure you`re talking about an AS3 only project? Does anyone can provide a full class.
    Everytime i try it it compiles fine but nothing shows up.

    Thanx

    Benz

    benjamin

    29 Nov 05 at 1:33 pm

  3. Hello,

    Will the Flex 2 compiler eventually target versions 7 and/or 8 of the Flash Player?

    Mike

    Mike

    29 Nov 05 at 2:30 pm

  4. Thanks for the tip Mike but according to that info it seems we need a Container to be able to attach the Button on stage, like in MXML projets. Is there a way to create one then instantiate it on runtime ?
    Thanks

    Francis Gabon

    29 Nov 05 at 2:45 pm

  5. You could use the method explained here to see the generated actionscript file and have a bit of a look around what mxml files produce. Might help understand whats going on:

    http://www.powersdk.com/ted/2005/11/flex-wizard-behind-curtain.php

    Campbell

    30 Nov 05 at 4:43 am

  6. Take that back seems you cant do it in flexbuilder 2 :o(

    Campbell

    30 Nov 05 at 4:53 am

  7. Aparently “-keep-generated-actionscript=true” is a compiler argument in Flex 2 but:

    “Normally, you would put an argument like that in the box provided on the
    Flex Compiler page of the project properties in Flex Builder. However, in
    the current alpha build, Flex Builder is not passing that through properly
    to the compiler. This will be fixed in a subsequent build.

    For now, you can use the mxmlc command-line compiler to view the generated
    ActionScript.


    Phil Costa
    Sr. Product Manager
    Macromedia”

    Campbell

    30 Nov 05 at 5:06 am

  8. This is my as3.0 sample.
    http://blog.naver.com/ecj2000

    This sample is show combinations of Marix, bitmap, realtime MP3 Spectrum.
    Just Look and feel AS3.0′ powers.

    cheol jin eom

    2 Dec 05 at 8:22 pm

  9. Hello,

    Almost a year later what do you know, well, I cannot find any info on how to do this “Using Flex Components in ActionScript Projects” can someone please send me an email with a clear example of how I can do this because I tried a lot of things including the explanation found here which almost worked

    http://www.moock.org/blog/archives/000197.html

    I was able to access the mx.controls but when I tried to create a control dynamically it was not shown on the stage ? pls send me an email

    Kind Regards,

    thanks.

    Flexer

    30 Nov 06 at 9:45 pm

  10. Hello,

    Almost 2 years later what do you know ;)

    I want to use a combobox and a button in a simple as3 project, possible? not possible?

    thanks,

    Sakri

    sakri

    29 Jun 07 at 3:48 am

  11. Anyone ever figure this out?

    Dave

    14 Sep 07 at 5:40 am

  12. Do anyone know, how to add MXML components like “panel, vbox etc” in pure ActionScript Flex Project?

    amitpal

    21 Jan 08 at 5:56 am

  13. Hi,

    I’m trying to make an AS Project in flex builder 2.01.

    All is fine i can use Tween of Flex but I can’t use Datagrid.
    Can you help me about that?

    In my source path I’ve

    ${FRAMEWORKS}\source
    ${FRAMEWORKS}\locale\en_US // To avoid

    And

    ${FRAMEWORKS}/libs/playerglobal.swc
    ${FRAMEWORKS}/libs/utilities.swc
    ${FRAMEWORKS}/libs/flex.swc
    ${FRAMEWORKS}/libs/framework.swc

    THe project compile weel but When i run the project i got this error:

    Error #1006: getInstance is not a function
    at mx.core::Singleton$/getInstance()[C:\Program Files\Adobe\Flex Builder 2\Flex SDK 2\frameworks\source\mx\core\Singleton.as:49]
    at mx.styles::CSSStyleDeclaration$cinit()
    at global$init()[C:\Program Files\Adobe\Flex Builder 2\Flex SDK 2\frameworks\source\mx\styles\CSSStyleDeclaration.as:75]
    at global$init()[C:\Program Files\Adobe\Flex Builder 2\Flex SDK 2\frameworks\source\mx\controls\dataGridClasses\DataGridColumn.as:151]
    at content.winners::Winners$iinit()[M:\flex workspaces\lunapark\Lunapark\src\content\winners\Winners.as:32]
    at Lunapark/setContent()[M:\flex workspaces\lunapark\Lunapark\src\Lunapark.as:118]
    at content.header::Header/content.header:Header::navigate()[M:\flex workspaces\lunapark\Lunapark\src\content\header\Header.as:111]

    Can you help me?

    Best regards

    Hadrien

    wouitmil

    27 Jan 08 at 5:13 pm

  14. And yet another year later… I searched entire google trying to find an answer to the same question: how to use mx.controls components in Flex AS project.

    It just doesn’t work for me, I keep getting a runtime error that styleManager is a bad descriptor (null aparently).. Here is the code example that breaks:

    package {
    import mx.controls.Button;
    import mx.core.Application;

    public class test2 extends Application
    {
    public var btn:Button;
    public function test2() {
    btn = new Button();
    btn.label=”OK”;
    addChild(btn);
    }
    }
    }

    It beaks with this runtime error:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at mx.core::UIComponent/getStyle()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7597]

    please help :)
    Thanks
    Henry

    Henry G

    3 Jan 09 at 11:14 pm

  15. I have not tried this, but I would say the problem is you need to create the correct hierarchy to attach the button too which I believe goes nativeWindow->application->panel->button

    none

    13 Jan 09 at 9:26 am

  16. A solution can be found here:
    http://ersatz.tv/2009/off-topic-flex-components-without-mxml

    This code snippet gives you the basic set of Flex components for use with ActionScript only.

    Herr Moose

    28 Jun 09 at 2:44 pm

Leave a Reply