flash on 2013-12-3
URL を開くサンプル
@author Hikipuro
♥0 |
Line 59 |
Modified 2013-12-03 20:23:25 |
MIT License
archived:2017-03-30 06:56:30
ActionScript3 source code
/**
* Copyright s8t1h12akj ( http://wonderfl.net/user/s8t1h12akj )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jdKA
*/
package
{
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
/**
* URL を開くサンプル
* @author Hikipuro
*/
public class Main extends Sprite
{
/**
* ボタン
*/
private var button1:SimpleButton;
/**
* ボタンのラベル
*/
private var buttonText1:TextField;
/**
* コンストラクタ
*/
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
/**
* 初期化イベント
* @param e
*/
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
// ボタンのラベルの作成
buttonText1 = new TextField();
buttonText1.autoSize = TextFieldAutoSize.LEFT;
buttonText1.text = "URL を開く";
buttonText1.selectable = false;
buttonText1.width = 40;
buttonText1.height = 20;
buttonText1.x = 125;
buttonText1.y = 110;
addChild(buttonText1);
// ボタンの作成
button1 = new SimpleButton();
button1.upState = makeRoundRect(0xDDDDDD, 100, 20, 10);
button1.overState = makeRoundRect(0xFFFFFF, 100, 20, 10);
button1.downState = makeRoundRect(0xBBBBBB, 100, 20, 10);
button1.hitTestState = button1.upState;
button1.addEventListener(MouseEvent.MOUSE_DOWN, onButtonMouseDown);
button1.x = 105;
button1.y = 110;
addChild(button1);
}
/**
* 角丸の図形を描いたスプライトを作って返す
* @param color 色
* @param width 幅
* @param height 高さ
* @param round 角丸の大きさ
* @return スプライト
*/
private function makeRoundRect(color:uint, width:int, height:int, round:int):Sprite
{
var s:Sprite = new Sprite();
s.graphics.lineStyle(2);
s.graphics.beginFill(color);
s.graphics.drawRoundRect(0, 0, width, height, round);
s.graphics.endFill();
s.alpha = 0.3;
return s;
}
/**
* ボタンが押された時のイベントハンドラ
* @param event
*/
private function onButtonMouseDown(event:MouseEvent):void
{
// google のトップページを新しいウインドウで開く
var url:String = "https://www.google.co.jp/";
var urlRequest:URLRequest = new URLRequest(url);
navigateToURL(urlRequest, "_blank");
}
}
}