Skip navigation
Currently Being Moderated

ActionScript Project

Nov 5, 2009 2:53 PM

I have an ActionScript Project and I have been running unit tests using the FlexUnit 4 integration in Flash Builder 4 Beta 2. These have been working great until I try to use UIImpersonator, which uses Flex classes and fails in my pure ActionScript project. (UIImpersonator works fine with a Flex Project.)

 

Since Flash Builder is for both Flex and ActionScript projects, I figured I would be able to use FlexUnit to equal extents. Is there an ActionScript project equivalent to UIImpersonator, or just a way to access the Stage?

 
Replies
  • Currently Being Moderated
    Nov 5, 2009 3:05 PM   in reply to ronzoni17

    Right now UIImpersonator has dependencies on UIComponent which is the reason it is only compiled into Flex projects. It is a goal to make this feature suitable for ActionScript projects. However, there will always be somethings that the Flex version can do that the ASOnly version cannot. For instance, binding and container based ideas.

     

    We will add a feature request to Jira for this so you can track out progress,

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 5, 2009 4:04 PM   in reply to ronzoni17

    http://www.uza.lt/codex/as3-global-object/

    Actually scratch that suggestion for the moment.

     

    I will work on a work around for you

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 8, 2009 9:58 AM   in reply to ronzoni17

    There is a version that will be available shortly with a proposed fix.

     

    Will post as soon as it is ready, and will appreciate if you can jump on testing it quickly when you can.

     

    Thanks,

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 21, 2010 6:12 PM   in reply to ronzoni17

    Gianni,

     

    Sorry, I haven't had a chance to document this yet, but, as you have seen, you can now call those UIImpersonator methods. There is one more requirement though to make this all work.

     

    Before you run your tests in an AS only project, you need to create the VisualEnvironment and pass it a reference to the stage. Here is a quick example from my testing:

     

                var environmentBuilder:IVisualEnvironmentBuilder = VisualTestEnvironmentBuilder.getInstance( this );

                var spt:Sprite = new Sprite();

                trace( UIImpersonator.numChildren );

                UIImpersonator.addChild( spt );

                trace( UIImpersonator.numChildren );

     

     

                var core:FlexUnitCore = new FlexUnitCore();

                core.addListener( new TraceListener() );

                core.run( FlexUnitIn360 );

     

    The *this* reference passed into the getInstance() method is the stage reference.  This interface could change slightly in the future, but this is the best solution I have been able to find so far.

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 25, 2010 10:07 AM   in reply to ronzoni17

    Gianni,

     

    It needs to be called before the core.run() is called like in my example.

     

    How are you running the tests, flash builder or another ide?

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 25, 2010 10:13 AM   in reply to ronzoni17

    Fair enough. I am still working with Adobe to see if they can call this automatically, however, you can actually use it without Adobe's auto-generated code. Will put together a sample for you.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 29, 2012 10:12 AM   in reply to ronzoni17

    I found this BDD project page, which includes a stage access example:

    Cuke4AS3 https://github.com/flashquartermaster/Cuke4AS3/

     

    [EDIT]

    After much research and complication, I ended up using a Singleton that provides a stage reference that was passed in from a `creationComplete` handler in my TestRunner.

     

    =======TestRunner.mxml==========================================

     

    <?xml version="1.0" encoding="utf-8"?>

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

        creationComplete="onCreationComplete()"

        xmlns:flexUnitUIRunner="http://www.adobe.com/2009/flexUnitUIRunner"

        styleName="flexUnitApplication"

        layout="absolute" height="800" width="1000">

        <mx:Script>

            <![CDATA[

                import org.flexunit.runner.FlexUnitCore;

                private var core:FlexUnitCore;

                public function onCreationComplete():void {

                    core = new FlexUnitCore();

                    core.addListener( new TraceListener() );

                    core.addListener( new UIListener( uiListener ));

                    new StageLocator(systemManager.stage);

                    core.run(MyTestSuite);

                }

            ]]>

        </mx:Script>

        <mx:Style>

            Application {

                   backgroundColor: #3872b2;

                   backgroundGradientColors: #3872b2, #0c1a3d;

                   backgroundGradientAlphas: 1, 1;

                   themeColor: #ffffff;

                   color: #444444;

                   fontFamily: "Myriad Pro Semibold";

                   fontSize: 12;

                }

        </mx:Style>

        <flexUnitUIRunner:TestRunnerBase id="uiListener" width="100%" height="100%" />

    </mx:Application>

     

    =======StageLocator.as==========================================

     

    package {

    import flash.display.Stage;

    public class StageLocator {

        public static var instance:StageLocator;

        public static var stage:Stage;

        public function StageLocator ($stage:Stage) {

            instance = this;

            stage = $stage;

        }

    }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 11:30 PM   in reply to ronzoni17

    There is a gist here: https://gist.github.com/1094408 that explains how to access the stage from a pure ActionScript project.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points