创建“加载文本”按钮时出现错误1119

时间:2012-03-09 19:33:59

标签: actionscript-3 flash actionscript

我正在创建的Flash动画的一部分涉及一个人们可以在记事本上书写的区域,保存他们的工作并在以后更新它。用户在运行文件之前将下载该文件,而不是从网页下载。这是我到目前为止的代码:

import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.display.MovieClip;
import flash.events.Event;

stop();

var MyNotes:FileReference = new FileReference()


Save_btn.addEventListener (MouseEvent.CLICK, SaveText);

function SaveText(Event:MouseEvent):void {
MyNotes.save(TypeOwn_txt.text, "MyNotes.txt");
}

Load_btn.addEventListener (MouseEvent.CLICK, LoadText);

function LoadText(Event:MouseEvent):void {
MyNotes.addEventListener(Event.SELECT, onFileSelected);
var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; .html;*.htm;*.php");
var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
MyNotes.browse([swfTypeFilter, allTypeFilter]);
}

function onFileSelected(event:Event):void
{
trace("onFileSelected");
MyNotes.addEventListener(Event.COMPLETE, onFileLoaded);
MyNotes.load();
}

function onFileLoaded(event:Event):void
{
var fileReference:FileReference=event.target as FileReference;
var data:ByteArray=fileReference["data"];
TypeOwn_txt.text=data.toString();
}

问题是我收到了“符号'结构摘要',图层'动作',第29帧,第19行1119:通过静态类型flash.events:MouseEvent的引用访问可能未定义的属性SELECT。 “关于行”MyNotes.addEventListener(Event.SELECT,onFileSelected);“。我已经做了一些研究,并且明白这与父母没有被识别为MovieClip有关,或者是那些沿着这条线的东西。我我仍然不确定,但我不知道如何继续!谢谢。

1 个答案:

答案 0 :(得分:0)

只是为了让你知道问题已经解决了,虽然我真的不知道怎么回事。我使用this site作为模板并向后工作。我将在下面列出工作代码,以防其他人使用。

import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.utils.ByteArray;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.display.MovieClip;

var myNotes:FileReference;

Load_btn.addEventListener(MouseEvent.CLICK, onLoadClicked);

function onLoadClicked(event:MouseEvent):void
{
    trace("onBrowse");
    myNotes=new FileReference();
    myNotes.addEventListener(Event.SELECT, onFileSelected);
    var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; *.html;*.htm;*.php");
    var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
    myNotes.browse([swfTypeFilter, allTypeFilter]);
}


function onFileSelected(event:Event):void
{
    trace("onFileSelected");

    myNotes.addEventListener(Event.COMPLETE, onFileLoaded);
    myNotes.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
    myNotes.load(); 
}

function onFileLoaded(event:Event):void
{
    var fileReference:FileReference=event.target as FileReference;
    var data:ByteArray=fileReference["data"];
    textArea.text=data.toString();
    myNotes.removeEventListener(Event.COMPLETE, onFileLoaded);
    myNotes.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
}

function onFileLoadError(event:Event):void
{
    myNotes.removeEventListener(Event.COMPLETE, onFileLoaded);
    myNotes.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);

    trace("File load error");
}   

Save_btn.addEventListener (MouseEvent.CLICK, SaveText);

function SaveText(Event:MouseEvent):void {
    myNotes=new FileReference();
    myNotes.save(textArea.text, "MyNotes.txt");
}

感谢所有贡献的人。