获取访问webservice的错误

时间:2010-04-08 12:02:59

标签: actionscript-3 flex3 mxml

我创建了webapplication,我收到错误: -

ypeError:错误#1009:无法访问空对象引用的属性或方法。     在FlexSBTSApp / displayString()[E:\ Users \ User1 \ Documents \ Flex Builder 3 \ FlexSBTSApp \ src \ FlexSBTSApp.mxml:38]     在FlexSBTSApp / ___ FlexSBTSApp_Button1_click()[E:\ Users \ User1 \ Documents \ Flex Builder 3 \ FlexSBTSApp \ src \ FlexSBTSApp.mxml:118]

我的代码是: -

    

   import mx.controls.*;


     [Bindable]
        private var childName:ArrayCollection;
     [Bindable]
        private var childId:ArrayCollection;  
        private var photoFeed:ArrayCollection;
        private var arrayOfchild:Array;
        [Bindable]
        private var childObj:Child; 
    public var user:SBTSWebService;

    public function initApp():void
    {
       user = new SBTSWebService();

       user.addSBTSWebServiceFaultEventListener(handleFaults);

    }

    public function displayString():void
    {
           // Instantiate a new Entry object.
           var newEntry:GetSBTSMobileAuthentication = new GetSBTSMobileAuthentication();
            newEntry.mobile=mobileno.text;
            newEntry.password=password.text;
            user.addgetSBTSMobileAuthenticationEventListener(authenticationResult);

            user.getSBTSMobileAuthentication(newEntry);

    }

    public function handleFaults(event:FaultEvent):void
    {
        Alert.show("A fault occured contacting the server. Fault message is: " + event.fault.faultString);
    }

    public function authenticationResult(event:GetSBTSMobileAuthenticationResultEvent):void
    {
        if(event.result != null && event.result._return>0) 
        {

           if(event.result._return > 0)
           {
             var UserId:int = event.result._return;
              getChildList(UserId);       
              viewstack2.selectedIndex=1;
           }
           else
           {
             Alert.show("Authentication fail");
           }


        }

    }
  public function getChildList(userId:int):void
  {
     var childEntry:GetSBTSMobileChildrenInfo = new GetSBTSMobileChildrenInfo();
     childEntry.UserId = userId;
     user.addgetSBTSMobileChildrenInfoEventListener(sbtsChildrenInfoResult);
     user.getSBTSMobileChildrenInfo(childEntry);
  }
   public function sbtsChildrenInfoResult(event:GetSBTSMobileChildrenInfoResultEvent):void
    {
        if(event.result != null && event.result._return!=null) 
        {

        arrayOfchild  = event.result._return as Array;
        photoFeed = new ArrayCollection(arrayOfchild);
        childName = new ArrayCollection();


       for( var count:int=0;count<photoFeed.length;count++)
       {
           childObj = photoFeed.getItemAt(count,0) as Child;
           childName.addItem(childObj.strName); 

       }

    }
    }

]]>

<mx:Panel width="500" height="300"
    headerColors="[#000000,#FFFFFF]">

    <mx:TabNavigator id="viewstack2" selectedIndex="0" creationPolicy="all" 
    width="100%" height="100%"> 
        <mx:Form label="Login Form">
         <mx:FormItem label="Mobile NO:">
            <mx:TextInput id="mobileno" />
         </mx:FormItem>
        <mx:FormItem label="Password:">
            <mx:TextInput displayAsPassword="true" id="password" />
       </mx:FormItem>
        <mx:FormItem>
            <mx:Button label="Login" click="displayString()"/>
       </mx:FormItem>
        </mx:Form>


           <mx:Form label="Child List">
              <mx:Label width="100%" color="blue" 
                   text="Select Child."/>


              <mx:RadioButtonGroup id="radioGroup"/>
                 <mx:Repeater id="fieldRepeater" 
                                dataProvider="{childName}">
                                <mx:RadioButton groupName="radioGroup" 
                                            label="{fieldRepeater.currentItem}" value="{fieldRepeater.currentItem}"/>
                 </mx:Repeater>


          </mx:Form>

          <mx:Form label="Child Information">



          </mx:Form>
          <mx:Form label="Trace Path">

          </mx:Form>
    </mx:TabNavigator>

</mx:Panel>

1 个答案:

答案 0 :(得分:0)

您的initApp()似乎无法从任何地方调用(除非它在您粘贴的脚本之外列出),因此当您尝试添加EventListener时,您的用户可能为null