Skip to main content
Known Participant
May 21, 2011
Question

html to as3

  • May 21, 2011
  • 3 replies
  • 1080 views

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

This topic has been closed for replies.

3 replies

Participating Frequently
May 21, 2011

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

Inspiring
May 21, 2011

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

kglad
Community Expert
Community Expert
May 21, 2011

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);

}

joshwwAuthor
Known Participant
May 21, 2011
No text available