html to as3
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
do i make a broswe button?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
AS3 has a very limited support for HTML tags. This support doesn't include form objects. So, the answer is "no".
Copy link to clipboard
Copied
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

