Asmi
Asmi

Reputation: 187

How to Access buttons and labels of one mxml file from another mxml file

I m completely fresher in Flex Programming, I have a FileUploadPanel.mxml which contains functionality of uploading, deleting and viewing one file only.. Now i need to modify the application to accommodate multiple attachments facility, So i created another panel ie MultiFileUpload.mxml, which has the functionality to get all attachment in form of List of Objects , and for each object-id I need to call the previous File Upload Panel, Every Thing is Working fine, but when i am accessing buttons and Labels of FileUpload.mxml it is throwing error:

1009- cannot access property and method of null object reference. 

code FileUploadPanel.mxml



 <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="492" height="46" >
        <mx:Label x="0" y="4" text="File Attachment:"/>
        <mx:Button x="93.5" y="2" label="Browse" id="btnBrowseView" click="__onBrowse();" enabled="true" width="67"/>
        <mx:Text x="264.5" y="4" width="100%" id="lbUploadFile" height="18 " />
        <mx:Button x="165" y="2" label="Upload" id="btnUpload" enabled="true" click="reserveAttachment();" width="67"/>
        <mx:Text x="10" y="25" width="100%" height="18" id="__status__" fontWeight="bold" color="#023AF1"/>
        <mx:Script>
            <![CDATA[


         public function SetAttachmentID(anAttachmentID: Number): void
            {               
                this.AttachmentID = anAttachmentID;
                lbUploadFile.text = "";  //here i am getting error
                __status__.text = "";
                if (AttachmentID != -1)
                {
                    m_data = new DocumentsAdt();
                    m_data.ConnectionIndex = ConnectionIndex;
                    m_data.OnLoadData = this.OnDoxLoaded;
                    m_data.LoadFromWebService(AttachmentID);

                    btnBrowseView.label = "View";
                    btnUpload.label = "Delete";
                    btnUpload.enabled = true;
                    btnUpload.visible = true;
                }
                else
                {   
                    btnBrowseView.label = "Browse";
                    btnUpload.visible = false;
                    btnUpload.label = "Upload";
                    btnUpload.enabled = false;
                    Init();
                }
            }
           </mx:Script>
</mx:Canvas>

Code MuliFileUpload.mxml

<?xml version="1.0" encoding="utf-8"?>

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" xmlns:BoycePanels="BoycePanels.*" xmlns:ns1="com.flextoolbox.controls.*" xmlns:ns2="com.adobe.flex.extras.controls.*" xmlns:ns3="BoycePanels.*">



    <mx:Script>
        <![CDATA[



            import Adt.Attachments.DocumentsAdt;

            import com.boycepensions.DocumentsService.DocumentsService;
            import com.boycepensions.DocumentsService.GetDocumentsRecordResultEvent;

            import mx.collections.ArrayCollection;
            private var m_data: DocumentsAdt = null;
            import mx.rpc.events.FaultEvent;
            import BoycePanels.FileUploadPanel;
            import mx.controls.Alert;

            public var ConnectionIndex: int = new int(0);
            public var AttachmentID: Number = new Number(-1);
            public var acDocList:ArrayCollection=null;
            public function Init():void
            {
                getDocs_Test();
            }

            public function getDocs_Test():void    
            {
                blah..blah..blah..
            }
            public function OnGetDocumentsRecord(event:GetDocumentsRecordResultEvent): void   
            {
               var  acDocList:ArrayCollection=new ArrayCollection();
                var m_data:DocumentsAdt=new DocumentsAdt();
                if (!CheckResult(event.result))         
                    return;         
                else
                {
                    acDocList=m_data.LoadDocumentsFromXML(event.result);          
                    for each(var obj:DocumentsAdt in acDocList)
                    {
                        var pnl:FileUploadPanel=new FileUploadPanel();
                        //pnl.OnReserveAttachmentDone=OnReserveAttachment;
                        pnl.Init();
                        pnl.SetAttachmentID(obj.Document_ID); //here it is throwing error
                    }
                }

            }  

Please suggest, i have already spent days and hours on it..

Upvotes: -1

Views: 309

Answers (1)

Pan
Pan

Reputation: 2101

You try to access lbUploadFile when it hasn't been initialized. So if you want the FileUploadPanel show on Stage, try add it to stage before call SetAttachmentID function, like this.

var pnl:FileUploadPanel=new FileUploadPanel();
this.addChild(pnl);//add it to where you want

If the pnl needn't show on stage, remove the lines where access the children.

Upvotes: 0

Related Questions