Hi,
I'm trying to test a component that has a Skin with 2 states, this skin contains a Button (btnMyButton) with "includeIn='state1'" and a TextInput (txtMyText) with "includeIn='state2'".
Clicking on the button triggers a method that changes the state, the problem is when I try to access the TextInput on the next step, I get a null pointer. It seems like the property that defines the state of the skin (myComp.skinState) has been updated properly, but the actual skin has not been updated and my TextInput has not been added to the stage. Does anyone know what the correct way for doing this is? Am I doing anything wrong?
See my code below.
Thanks.
- MyCompTest.as
[Before( async, ui )]
public function setUp() : void
{
myComp = new MyComp();
myComp.setStyle( "skinClass", MyCompSkin );
Async.proceedOnEvent( this, myComp, FlexEvent.CREATION_COMPLETE );
UIImpersonator.addChild( myComp );
}
[Test( async, ui )]
public function testOpenCloseMenu() : void
{
Async.handleEvent( this, myComp.btnMyButton, MouseEvent.CLICK, handleClickEvent, 500 );
myComp.btnMyButton.dispatchEvent( new MouseEvent( MouseEvent.CLICK ));
}
protected function handleClickEvent( event : Event, passThroughData : Object ) : void
{
Assert.assertEquals( "1-The state is incorrect", "open", myComp.skinState ); // skinState has the correct value, but myComp.skin.currentState hasn't
Async.handleEvent( this, myComp.txtMyText, MouseEvent.ROLL_OUT, handleRollOutEvent, 500 );
myComp.txtMyText.dispatchEvent( new MouseEvent( MouseEvent.ROLL_OUT )); // txtMyText is null at this point!
}
protected function handleRollOutEvent( event : Event, passThroughData : Object ) : void
{
Assert.assertEquals( "2-The state is incorrect", "closed", myComp.skinState );
}
- MyComp.as
override protected function getCurrentSkinState() : String
{
return skinState;
}