2016-05-10 19 views
-3

私は私のコンポーネントのサイズを変更するために私のアプリのリサイズハンドラを使用しますが、このエラーを投げている:ここでは「nullオブジェクト参照」エラー

TypeError: Error #1009: Cannot access a property or method of a null object reference 

は私のコードです:

<?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" minWidth="955" minHeight="600" 
      resize="application2_resizeHandler(event)" > 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 

    <fx:Script> 
     <![CDATA[ 
      import mx.events.FlexEvent; 
      import mx.events.ResizeEvent; 

      private var employeeName:String = 'ravi'; 

      protected function application2_resizeHandler(event:ResizeEvent):void 
      { 
       mainGroup.width = stage.width - 10; 
       mainGroup.x = 5;      
      } 

     ]]> 
    </fx:Script>  
    <s:Group width="100%" height="100%"> 
     <s:VGroup id="mainGroup" > 
      <s:Label id="employeeNameLabel" text="{employeeName}" /> 
      <s:Label id="departmentLabel" /> 
     </s:VGroup> 

     <s:Button id="getData" /> 
    </s:Group> 
</s:Application> 
+1

エラーは何ですか? –

+0

あなたはより具体的で、あなたが理解していないヌルオブジェクト参照のどの部分を説明するべきですか? – csmckelvey

答えて

-1

あなたが得ましたオブジェクトの作成前にresizeイベントが発生したため、#1009エラーが発生します。ですから、ステージオブジェクトを使用できるように、アプリケーションがステージに追加されるのを待つ必要があります。

そのために

、私はあなたがあなたのコンポーネントのサイズを変更するresizeイベントを追加することができ、最高のイベントがapplicationCompleteイベントだと思い...

ですから、たとえば次のように行うことができます。

<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" minWidth="955" minHeight="600" 
    applicationComplete="application2_applicationCompleteHandler(event)" > 
その後、

protected function application2_applicationCompleteHandler(event:FlexEvent):void 
{ 
    // if you want you can resize your component for the 1st time 
    // by calling the application2_resizeHandler() function 
    application2_resizeHandler(new ResizeEvent(ResizeEvent.RESIZE)); 

    // add the resize event listener to your app 
    event.target.addEventListener(ResizeEvent.RESIZE, application2_resizeHandler); 
} 

役立つことを願って。

+0

私のポストを落とした人が何が間違っているのか教えていただければ幸いです。 – akmozo

関連する問題