문제

I have this App.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx">
    <s:Button id="bt" label="click me"/>
</s:Application>

And this test case:

package flexUnitTests
{
    import flexunit.framework.Assert;

    public class AppTest
    {       
        [Test]
        public function testApp():void
        {
            var app:App = new App();
            Assert.assertNotNull(app.bt);
        }
    }
}   

But app.bt is null. I want to access the button :(

도움이 되었습니까?

해결책

Short Answer:

The life cycle methods have not run on app; so no createChildren() method was executed in order to create the child component of bt.

Longer Answer:

Things get slightly more complicated with the main application file, as it there is no higher level Flex component in the display hierarchy. I'm unclear on all specifics, but..

I think the Flex Compiler does some magic to set up this component--and the Flex Framework--that help makes the whole app work. You are, in essence, bypassing that work by creating your own instance of the component.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top