忍者ブログ
Flex,Java,Html など、調べた事のメモ帳です。 間違ってたらゴメンなさい。
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

mxml ソースにボタンがあり、クリックでロジック実行するための雛形

ボタンをクリックでラベルテキストを変更の例

サンプルは、パッケージ sample.logic.hellotest に、HelloButton.as を用意する。
IMXMLObject をインターフェースに持つようにクラスを作る。

-------------- HelloButton.as ----------------
package sample.logic
{
   import mx.core.IMXMLObject;
   import spark.components.Label;

   public class HelloButton implements IMXMLObject{
      private var view:HelloFx;
      
      public function HelloButton(){
      }
      public function initialized(document:Object, id:String):void{
      }
      public function buttonClickHandler(label:Label):void{
         label.text = "Test!!";
      }
   }
}

----------------------------------------------
ビューとしての mxml は、以下のように記述する。
  (デスクトップアプリとして作ったmxml)
xmlns で、作成した as のパッケージ配下を名前空間として宣言し
Declarations タグで作成したクラス宣言をして、Button の click 属性で呼び出す

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" 
                       xmlns:hellotest="sample.logic.hellotest.*">
<fx:Declarations>
   <hellotest:HelloButton id="hello"/>
</fx:Declarations>


<s:Button id="hellobutton" x="60" y="15" label="Hello" 
          click="hello.buttonClickHandler(message)"/>
<s:Label id="message" x="60" y="53" width="70" height="20"/>

こちらからダウンロード
http://away3d.com/download/

デモはこちらから
http://away.kiev.ua/away3d/techdemos/engine/



<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">

  <mx:Script>
    <![CDATA[
      import mx.collections.ArrayCollection;
      private var directory:File = File.documentsDirectory;

      private function initApp():void {
          directory.addEventListener(Event.SELECT, directorySelected);
      }
    
      private   function onClick():void {
        try
        {
            directory.browseForDirectory("Select Directory");
        }
        catch (error:Error)
        {
            trace("Failed:", error.message)
        }

      }

      private function directorySelected(event:Event):void {
          directory = event.target as File;
          var files:Array = directory.getDirectoryListing();
          var filenames:ArrayCollection = new ArrayCollection();

          for (var i:uint = 0; i < files.length; i++) {
            filenames.addItem(files[i].name);
          }
          fileList.dataProvider = filenames;
      }  
    ]]>
  </mx:Script>

  <mx:Button label="open" click="onClick()"/>
  <mx:List id="fileList" width="100%" height="100%"/>
    
</mx:WindowedApplication>
//半角数値のみ入力可能
<TextInput restrict="[0-9]" maxChars="35"/>

//半角英字の大文字と半角空白のみ入力可能
<TextInput restrict="[A-Z-[ ]]" maxChars="35"/>







// 読み書き対象となるファイルのインスタンス
var file:File = new File("C:\\Temp\\test.txt");

// FileStreamクラスのインスタンス作成
var stream:FileStream = new FileStream();

// (1) 対象ファイルへのストリームをオープン
stream.open(file, FileMode.READ);

...
// (2) ファイルの読み書きを行う
...

// ストリームをクローズする
stream.close();







ブログランキング
にほんブログ村 IT技術ブログ IT技術メモへ
 
カレンダー
03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
人気ブログランキング
ブログランキング ブログランキング
最新TB
ブログ内検索
PR
ATOM  
ATOM 
RSS  
RSS 
Copyright ©   プログラムメモ   All Rights Reserved
Design by MMIT  Powered by NINJA TOOLS
忍者ブログ [PR]