如何更新我的 status_text 框(这是一个 TextInput 区域),同时仍然坚持 MVC 架构

发布于 2024-11-17 12:56:36 字数 2505 浏览 6 评论 0原文

我有这个框,可以让用户随时了解某些数据库更改的业务流程的状态。我尝试使用 Flex 忠实于 MVC 架构。我收到编译错误:

1119:通过静态类型 String 的引用访问可能未定义的属性文本。

以下是 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';
        }
    }
}

TextInput 区域位于 MXML 组件中因此:

<?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>

那么我如何从 ActionScript 更新这个框呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ま昔日黯然 2024-11-24 12:56:36

编译器错误是因为您将 status_txt 转换为字符串,而它应该是 TextInput。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文