Posted By

daisuke103 on 04/04/08


Tagged

file textmate button upload local up as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


AS3 ローカルファイル参照ボタン


 / Published in: Other
 

  1. package {
  2. import flash.display.*;
  3. import flash.events.*;
  4. import flash.net.FileReference;
  5. import flash.text.*;
  6. public class FileSelect extends Sprite {
  7. private var tf:TextField = new TextField();
  8. private var fileReference:FileReference = new FileReference();
  9. public function FileSelect( ) {
  10. addChild(tf);
  11. tf.autoSize = TextFieldAutoSize.LEFT;
  12. tf.text="press button";
  13.  
  14. // ボタンの作成
  15. var button:SimpleButton = new SimpleButton( );
  16. button.x = 20;
  17. button.y = 40;
  18.  
  19. button.upState = createCircle( 0x00FF00, 15 );
  20. button.overState = createCircle( 0xFFFFFF, 16 );
  21. button.downState = createCircle( 0xCCCCCC, 15 );
  22. button.hitTestState = button.upState;
  23.  
  24. // マウスクリックイベントのリスナ登録
  25. button.addEventListener( MouseEvent.CLICK, handleClick );
  26. addChild( button );
  27.  
  28. }
  29. private function createCircle( color:uint, radius:Number ):Shape {
  30. var circle:Shape = new Shape( );
  31. circle.graphics.lineStyle( 1, 0x000000 );
  32. circle.graphics.beginFill( color );
  33. circle.graphics.drawCircle( 0, 0, radius );
  34. circle.graphics.endFill( );
  35. return circle;
  36. }
  37. private function handleClick( event:MouseEvent ):void {
  38. // ファイル選択イベントのリスナ登録
  39. fileReference.addEventListener(Event.SELECT, onSelectFile);
  40. fileReference.browse();
  41. }
  42. private function onSelectFile( event:Event ):void {
  43. // 選択されたファイル名の表示
  44. tf.text = fileReference.name;
  45. }
  46. }
  47. }

Report this snippet  

You need to login to post a comment.