URLとそのパラメータ取得の練習失敗

by siouxcitizen forked from Twitter投稿機能の練習 (diff: 30)
♥0 | Line 71 | Modified 2010-12-08 19:11:39 | MIT License
play

ActionScript3 source code

/**
 * Copyright siouxcitizen ( http://wonderfl.net/user/siouxcitizen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8sOO
 */

// forked from siouxcitizen's Twitter投稿機能の練習
//URLとそのパラメータ取得の練習失敗
//コード残しておいてそのうち続きの作業予定
package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    import flash.net.URLRequest;
    import flash.net.navigateToURL;
    import flash.utils.escapeMultiByte;
//import net.wonderfl.utils.WonderflSWFUrl;
    public class ButtonTest extends Sprite {
        
        private var button : SimpleButton;//ボタン 
        private var label : TextField;    //ラベル
        private var urlDispLabel : TextField;    //ラベル
        
        public function ButtonTest() {
            //URLを取得する
            var url:String = loaderInfo.url;
            //FlashVarsを取得する
            var flashvars:String = loaderInfo.parameters.flashvars;
            //GETクエリを取得する
            var getquery:String = loaderInfo.parameters.getquery;

//var CODE_PAGE:String = "http://wonderfl.net/code/3b5361b2e8435d6501cd84edde1753c37f441efe";
//swfパスが取得できる
//var path:String = WonderflSWFUrl.getURLFromPageURL(CODE_PAGE);
//urlDispLabel.text = path;

            urlDispLabel = new TextField;
            urlDispLabel.width = 500;
            urlDispLabel.text = "URL :" + url + "\n" + 
                                "Flash Vars :" + flashvars + "\n" + 
                                "GET Query :" + getquery + "\n";
            urlDispLabel.y = 100;
            addChild(urlDispLabel);

            label = new TextField;
            label.text = "TweetTest!";
            addChild(label);
            
            button = new CustomButton("Tweet");
            button.y = 20;

            button.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
            button.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
            addChild(button);
        }
   
        //マウスダウンイベントの処理
        private function onMouseDown(evt:MouseEvent):void {
            label.text = "Tweet!!!";
            var comment:String = "FlashからTwitterへの投稿機能のテストです ";
            var post:String = comment + " " + "http://wonderfl.net/c/8sOO?testType=twitterReadTest" + " " + "#wonderfl ";
            navigateToURL(new URLRequest("http://twitter.com/home?status=" + escapeMultiByte(post)), "_blank");
        }

        //マウスアップイベントの処理
        private function onMouseUp(evt:MouseEvent):void {
            label.text = "TweetTest!";
        }        
    }
}

import flash.display.*;
import flash.system.*;
import flash.text.*;

//カスタムボタン
class CustomButton extends SimpleButton { 
        //コンストラクタ    
        public function CustomButton(label:String="") {
            //状態
            upState = makeSprite(label,0x00FFFF);
            overState = upState;
            downState = makeSprite(label,0x00FF00);
            hitTestState = upState;
        }

        //ボタン用スプライト作成
        private function makeSprite(text:String,color:uint):Sprite{
            //ボタン用ラベル作成
            var label : TextField = new TextField();
            label.text = text;
            label.autoSize = TextFieldAutoSize.CENTER;
            label.selectable = false;

            //ボタン用スプライト作成
            var sp:Sprite = new Sprite();
            sp.graphics.beginFill(color);
            sp.graphics.drawRoundRect(0, 0, 100, 20, 15);
            sp.graphics.endFill();
            sp.alpha = 0.8;            
            sp.addChild(label);
            
            //ラベル用フォーマット設定
            var format:TextFormat=new TextFormat();
            format.font = "Courier New";
            format.bold = true;
            format.size = 13;
            label.setTextFormat(format);

            return sp;
        }    
}

Forked