• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

flexunit stage null reference

New Here ,
May 02, 2011 May 02, 2011

Copy link to clipboard

Copied

I am trying to test some of my AS classes in flexunit.  Some of the methods reference the stage from components that are passed to it. When I set up the flexunit testing application I use the following code:

core = new FlexUnitCore();

core.visualDisplayRoot = this;

core.addListener( new UIListener( uiListener ));

However, I still get a null reference exception whenever the stage is referenced.  I was wonding if anyone knew what is going on or what I am doing wrong.

Thanks!

TOPICS
FlexUnit

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 02, 2011 May 02, 2011

Copy link to clipboard

Copied

What is the object that 'this' refers to? Does that code exist on the main sprite, somewhere else?

Glad to help just need a bit more info,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 02, 2011 May 02, 2011

Copy link to clipboard

Copied

The previous code is in the creationComplete event function for my test runner. (I used the flexunit 4.1 turnkey example)

The "this" is the runner application.

Then in the test I would have:

[Test]

public function testFunct():void

{

    //this class stores various elements so that other classes can referance them

    Control.initApp(new Image());

    //this fails when testing

    Assert.assertNotNull(Control.getImageContainer().stage);

}

I am not sure why the assert equals null.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 02, 2011 May 02, 2011

Copy link to clipboard

Copied

LATEST

Okay, a few things.

If you are using Flex, you don't need to set the visualDisplayRoot. That is for ActionScript only projects.

Second, display objects in Flash don't have access to the stage until they are on the display list. So, saying

new Image() won't add that item to the display list.

I am not sure what Control.initApp() does, but in one of your unit tests, they way you get something on the display list is to use the UIImpersonator:

UIImpersonator.addChild( someImage );

After that someImage would have access to the stage. However, bigger problem. Unit tests are about isolation and if you components need to get out to the stage or if Control.initApp() somehow adds the item directly to the display list you are going to continue to have different issues as you won't be able to keep things in isolation to test.

Hope that clarifies a little bit,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines