Search code examples
actionscript-3apache-flexmodel-view-controllerflex3mxml

How do I update my status_text box (which is an TextInput area) while still holding true to MVC architecture


I have this box which keeps the user updated on the status of the business process of some database changing. I am trying to stay true to the MVC architecture using Flex. I am getting a compile error:

1119: access of possibly undefined property text through a reference with a static type String.

Here is the code for the BrowseButtonClickEvent.as:

package business.events
{
    import com.adobe.cairngorm.control.CairngormEvent;

    import flash.events.DataEvent;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.net.FileFilter;
    import flash.net.FileReference;

    public class BrowseButtonClickEvent extends CairngormEvent
    {
        static public var EVENT_ID:String="browseButtonClick";
        public var file:FileReference=null;
        private var excelFilter:FileFilter = new FileFilter("*.xlsx", "*.xlsx;*.xls;");
        public var status_txt:String;

        public function BrowseButtonClickEvent()
        { 
            super(EVENT_ID);
            file = new FileReference();
            file.addEventListener(Event.SELECT, fileSelected);
            file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadDataComplete);
            file.addEventListener(Event.COMPLETE, uploadComplete);
            file.addEventListener(IOErrorEvent.IO_ERROR, handleError);
            file.browse([excelFilter]);
        }

        public function handleError(event:IOErrorEvent):void 
        {
            status_txt.text = 'ERROR: ' + event.text + '';
        }
        public function fileSelected(event:Event):void
        {
            file = FileReference(event.target);
            file_txt.enabled = true;
            file_txt.text = file.name;
            status_txt.text = 'upload file: '+ file.name  + ''; 
        }

        public function uploadDataComplete(event:DataEvent):void 
        {
            var result:XML = new XML(event.data);
            status_txt.text += 'Upload Data Complete'
            status_txt.text += 'RESULT: ' + result.toString()  + ''
            status_txt.text += 'STATUS: ' + result.status + '';
            status_txt.text += 'MESSAGE: '+ result.message;
        }

        public function uploadComplete(event:Event):void 
        {
            status_txt.text += 'Upload complete';
        }
    }
}

The TextInput area is located in a MXML Component as such:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="382" height="232">
    <mx:TextInput x="0" y="0" width="382" height="232" enabled="true" editable="false" id="status_txt"/>
</mx:Canvas>

So how do I update this box from the ActionScript?


Solution

  • The compiler error is because you have cast status_txt as a String when it should be a TextInput.