Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

html to as3

New Here ,
May 21, 2011 May 21, 2011

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

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2011 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 21, 2011 May 21, 2011
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 21, 2011 May 21, 2011

do i make a broswe button?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2011 May 21, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2011 May 21, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 21, 2011 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines