-
1. Re: flexunit stage null reference
Michael Labriola May 2, 2011 12:55 PM (in response to chrise524)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
-
2. Re: flexunit stage null reference
chrise524 May 2, 2011 1:53 PM (in response to Michael Labriola)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.
-
3. Re: flexunit stage null reference
Michael Labriola May 2, 2011 1:56 PM (in response to chrise524)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

