6 Replies Latest reply: May 21, 2011 4:25 PM by kglad RSS

    html to as3

    joshww Community Member

      anyway to put the following in AS3

       

       

      "


      <form action="upload_file.php" method="post"
      enctype="multipart/form-data">
      <label for="file">Filename:</label>
      <input type="file" name="file" id="file" />
      <br />
      <input type="submit" name="submit" value="Submit" />
      </form>

      "

       

      thanks

      josh

        • 1. Re: html to as3
          kglad CommunityMVP

          create an input textfield (eg, tf) for the file name and use:

           

          submit.addEventListener(MouseEvent.CLICK,f);

           

          function f(e:MouseEvent):void{

          var urlLDR:URLLoader=new URLLoader();

          var urlReq:URLRequest=new URLRequest();

          var urlVar:URLVariables=new URLVariables();

          urlVar.name=tf.text;

          urlReq.url="upload_file.php";

          urlReq.method="POST";

          urlReq.data=urlVar;

          urlLDR.load(urlReq);

          }

          • 2. Re: html to as3
            Andrei1 Community Member

            AS3 has a very limited support for HTML tags. This support doesn't include form objects. So, the answer is "no".

            • 3. Re: html to as3
              joshww Community Member
              • 4. Re: html to as3
                joshww Community Member

                do i make a broswe button?

                • 5. Re: html to as3
                  Peter Blazejewicz Community Member

                  Hi Josh,

                   

                  there is no direct translation from html form input of type "file" into single line code in ActionScript. But the same feature is wrapped into flash.net.FileReference object:

                  http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference .html

                  - on user mouse click (required due to security restrictions in Flash runtime) create instance of FileReference

                  - call "browse" method to let user choose what file to upload

                  - if "browse" call returns true you could create upload URLRequest, set data (as in previous sample) and call upload(...) method

                  - wait for Event.COMPLETE to clear variables created for upload feature,

                  Similiary to HTML/JavaScript you won't have access to full path of selected file if movie is played within Flash runtime (security feature). If you require more information about file, its location, ect you would need to built AIR runtime based application.

                   

                  do i make a broswe button?

                  yes, in Flash runtime you would require button action to be wired to start file upload - so you need e.g. Button with MouseEvent.CLICK wired to it to start entire process (unless I'm missing something changed in player )

                   

                  regards,

                  Peter

                  • 6. Re: html to as3
                    kglad CommunityMVP

                    you'll need to use the filerefrence class if you want to open a browse-for-file system dialogue box so users can navigate to a file.