如何在Flash中加载用户的文件?

发布于 2024-12-07 15:36:35 字数 202 浏览 2 评论 0原文

我想在应用程序初始化后立即加载用户的文件。我有这样的代码:

fll = new FileReference();          
fll.browse([new FileFilter("Text *.txt", "*.txt")]);

按下某个按钮时它工作正常,但是当我将它放入框架的代码中时,它不起作用。我该怎么做?

I would like to load a user's file right after the app is inicialized. I have this code:

fll = new FileReference();          
fll.browse([new FileFilter("Text *.txt", "*.txt")]);

It works fine when some button is pressed, but when i just put it inside the frame's code, it doesnt work. How can i do it?

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

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

发布评论

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

评论(2

邮友 2024-12-14 15:36:35

出于安全原因,此函数仅适用于用户交互(鼠标单击、按键等),因此当您将其粘贴到常规框架脚本中时它将不起作用。

This function works only on user interaction (mouse click, key press etc) for security reasons, so it won't work when you paste it in regular frame script.

撕心裂肺的伤痛 2024-12-14 15:36:35
   Try this code, hopefully this will work for you:       

   import flash.text.*;
   import flash.net.FileReference;

   var tf:TextField = new TextField();
   tf.width = 350
   tf.height = 350
   tf.multiline=true;
   tf.border = true
   addChild(tf);

   var fileReference:FileReference = new FileReference();
   var fileFilter:FileFilter=new FileFilter("Images","*.txt");
   fileReference.addEventListener(Event.SELECT, onSelectFile);
   fileReference.addEventListener(Event.COMPLETE,onFileComplete);
   bBrowse.addEventListener(MouseEvent.MOUSE_DOWN, browseFile);

   function onFileComplete(event:Event):void 
   {
      tf.htmlText = "opening: "+fileReference.name+"<br>"
      var bytes:ByteArray=fileReference.data;
      var newtext:String=fileReference.data.readMultiByte(fileReference.data.length,"gb2312");
      //var newtext:String = fileReference.data.readUTFBytes(fileReference.data.length)
      tf.appendText(newtext);
    }

    function browseFile(e:MouseEvent) 
    {
        fileReference.browse([fileFilter]);
    }

    function onSelectFile(event:Event):void 
    {
         fileReference.load();
    }
   Try this code, hopefully this will work for you:       

   import flash.text.*;
   import flash.net.FileReference;

   var tf:TextField = new TextField();
   tf.width = 350
   tf.height = 350
   tf.multiline=true;
   tf.border = true
   addChild(tf);

   var fileReference:FileReference = new FileReference();
   var fileFilter:FileFilter=new FileFilter("Images","*.txt");
   fileReference.addEventListener(Event.SELECT, onSelectFile);
   fileReference.addEventListener(Event.COMPLETE,onFileComplete);
   bBrowse.addEventListener(MouseEvent.MOUSE_DOWN, browseFile);

   function onFileComplete(event:Event):void 
   {
      tf.htmlText = "opening: "+fileReference.name+"<br>"
      var bytes:ByteArray=fileReference.data;
      var newtext:String=fileReference.data.readMultiByte(fileReference.data.length,"gb2312");
      //var newtext:String = fileReference.data.readUTFBytes(fileReference.data.length)
      tf.appendText(newtext);
    }

    function browseFile(e:MouseEvent) 
    {
        fileReference.browse([fileFilter]);
    }

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