forked from: flashでソーシャルボタンの実装 on wonderfl build flash online
...
@author AsaToBan And Whaison
// forked from whaison's flashでソーシャルボタンの実装 on wonderfl build flash online
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.TextField;
import flash.utils.escapeMultiByte;
import flash.external.ExternalInterface;
/**
* ...
* @author AsaToBan And Whaison
*/
public class Main extends MovieClip
{
private var URL:String = "http://whaison.jugem.jp/";
private var worlds:MovieClip;
private var btnArr:Array;
private var buildY:int;
public function Main()
{
init();
worlds=this
}
private function init():void
{
buildY=10
btnArr = new Array()
_setupBTN("t_btn", "Twitter")
_setupBTN("f_btn", "FACEBOOK")
_setupBTN("m_btn","MIXI")
}
private function shareTwitter(e:MouseEvent):void
{
navigateToURL(
new URLRequest(
"http://twitter.com/share?text=abcd "
+ escapeMultiByte("tweet-test")
+ "&url=" + escapeMultiByte(URL)
+ "&via=" + escapeMultiByte("whaison")
)
);
}
public function shareFacebook(evt:Event = null):void
{
navigateToURL(
new URLRequest(
"http://www.facebook.com/sharer.php?"
+ "u=" + escapeMultiByte(URL)
)
)
}
private function shareMixi(e:MouseEvent):void
{
//バスコードは登録したものをいれてください
var passCode:String = "20a9551a2cc4d77b35d6dc8ad9fff5db74b77186";
navigateToURL(
new URLRequest(
"http://mixi.jp/share.pl" +
"?u=" + escapeMultiByte(URL) +
"&k=" + passCode
)
)
}
///////////////////////////////以下ボタン作るだけのFunction whaison
private function _setupBTN(name:String,label:String):void{
var button:Sprite = new Sprite();
button.graphics.lineStyle(1, 0x000000);
button.graphics.beginFill(0x000000);
button.graphics.drawRoundRect(0, 0, 100, 20, 5, 5);
button.graphics.endFill();
button.name=name
//worlds.addChild(button);
addChild(button);
btnArr.push(button)
button.x = 20;
buildY+=30
button.y = buildY
button.mouseChildren = false;
button.buttonMode = true;
var field:TextField = new TextField();
field.width = 100;
field.height = 20;
field.htmlText = "<p align='center'><font face='_sans'>"+label+"</span></p>";
field.textColor = 0xFFFFFF;
button.addChild(field);
button.addEventListener(MouseEvent.CLICK,ClickHandler);
}
private function ClickHandler(e:MouseEvent):void
{
switch (e.currentTarget.name)
{
case "t_btn":
shareTwitter(e)
break;
case "f_btn":
shareFacebook(e)
break;
case "m_btn":
shareMixi(e)
break;
default:
trace("デフォルトだよん")
break;
}
}
}
}