Re: [問題]怎麼連接 FB登入? 並分享照片~
有找到coding ~~
但遇到問題
TweenPlugin.activate([ShortRotationPlugin, TransformAroundPointPlugin, TransformAroundCenterPlugin]);
/**
* ...
* @author Ray
*/
var fb:WebFaceBook;
var _nameMc:NameMc;
var _userName:String;
var _sw:Number;
var _sh:Number;
var _vector:Vector.<Friend>;
var _i:int = 0;
var _titelMc:titelTxt;
var _loader2:Loader;
var _loader3:Loader;
var _len:int = 0;
var _txt:TextField;
var _loadMc:LoadIn;
var _loading:Loading;
//-----朋友名子mc------
var _ball:Ball;
var _ballContaner:Sprite;
//-----火燒用-----
var _card:CardMc;
var _bimp:Bitmap;
var _smokerMc:SmokerMc;
var _rayCard:RayCard;
var _rayContaner:Sprite;
var _contaner:Contaner=new Contaner();
var _centerX:Number;
var _centerY:Number;
var _num:int = 13;
var _agrUtil:Number;
var _radius:Number = 250;//直徑
var _timerA:Timer=new Timer(3000,1);
var _timerB:Timer=new Timer(6000,1);
var _timerC:Timer=new Timer(4000,1);
var _timerD:Timer=new Timer(6000,1);
var _timerE:Timer=new Timer(3000,1);
function FbMain() {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
function init(e:Event=null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
_sw = 800;
_sh = 600;
// fb初始化
fb = new WebFaceBook("261569630531690");
//trace(fb.hasLogin)
fb.addEventListener(FaceBook_INIT.INIT_SUCCESS, onINIT_SUCCESS);
}
function onINIT_SUCCESS(e:FaceBook_INIT):void {
fb.login();
fb.addEventListener(FaceBook_Login.LOGIN, onLoginHandler);
}
function onLoginHandler(e:FaceBook_Login):void {
createIndex();
}
function createIndex():void {
//取得個人資料
fb.getUser();
fb.addEventListener(ResUserEvent.RESULT, onUserEvent);
}
function onUserEvent(e:ResUserEvent):void {
fb.removeEventListener(ResUserEvent.RESULT, onUserEvent);
_nameMc = new NameMc();
_nameMc.x = _sw / 2;
_nameMc.y = _sh / 2;
addChild(_nameMc);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownHandler)
_userName = e.user.name + "";
}
function onKeyDownHandler(e:KeyboardEvent):void {
if (e.keyCode == Keyboard.ENTER && _nameMc.nameTxt.text ==_userName) {
_nameMc.poTxt.text = "";
TweenMax.to(_nameMc, .5, { scaleX:1.5, scaleY:1.5, autoAlpha:0, ease:Bounce.easeOut } );
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDownHandler);
_titelMc = new titelTxt();
_titelMc.x = _sw / 2;
_titelMc.y = _sh / 2;
addChild(_titelMc);
TweenMax.to(_titelMc, .5, { delay:1, onComplete:gogo } );
//取得朋友資料
fb.getFriends();
fb.addEventListener(ResFriendsEvent.RESULT,onRESULT);
//trace(_userName);
}else {
_nameMc.poTxt.text="請輸入你FB正確的名子"
}
}
function onRESULT(e:ResFriendsEvent):void {
_vector = new Vector.<Friend>;
_vector = e.friends.list;
_len = _vector.length;
fb.removeEventListener(ResFriendsEvent.RESULT, onRESULT);
//txtEvent(_len + "");
}
function gogo():void {
TweenMax.to(_titelMc, .5, { alpha:0 } );
removeChild(_titelMc);
//顯示Loading
_loading = new Loading();
_loading.x = _loading.width;
_loading.y = _sh -52;
_loading.scaleX = _loading.scaleY = 0.7;
addChild(_loading);
TweenMax.from(_loading, .5, { alpha:0 } );
playFlashBanner();
}
function playFlashBanner():void {
_centerX = _sw / 2;
_centerY = _sh / 2;
_smokerMc = new SmokerMc();
_smokerMc.x = _centerX;
_smokerMc.y = _centerY;
_rayCard = new RayCard();
_rayCard.x = _centerX-_rayCard.width/2;
_rayCard.y = _centerY-_rayCard.height/2;
_rayCard.alpha = 0;
//取得各人大頭貼
_loader2 = new Loader();
_loader2.load(new URLRequest("https://graph.facebook.com/" + fb.uid + "/picture?type=normal"));
_loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteLoader2);
}
function txtEvent(pString:String):void {
_txt = new TextField();
_txt.defaultTextFormat = new TextFormat("", 30, 0xffffff);
_txt.x = _sw/2;
_txt.y = _sh / 2;
_txt.text = pString;
addChild(_txt);
}
function onCompleteLoader2(e:Event):void {
var $LL:Loader = LoaderInfo(e.currentTarget).loader;
$LL.alpha = 0;
addChild(_rayCard);
addChild($LL);
$LL.x = _rayCard.x + (180 + (220 / 2 - $LL.width / 2));
$LL.y = _rayCard.y + 50;
TweenMax.to($LL,0.1,{transformAroundCenter:{scaleX:0, scaleY:0}})
TweenMax.to(_rayCard,0.1,{transformAroundCenter:{scaleX:0, scaleY:0}})
//$LL.unload();
setOverItem();
}
function setOverItem():void {
_contaner.x = 800 / 2 ;
_contaner.y = 600 / 2;
addChild(_contaner);
_ballContaner = new Sprite();
this.addChildAt(_ballContaner, 0);
_agrUtil = Math.PI*2 / _num;
for (var i:int = 0; i < _num; i++ ) {
//---抓圖片---
var $loader:Loader = new Loader();
$loader.load(new URLRequest(_vector[i].headImage(1)+""));
$loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
}
for (i = 0; i < 30; i++ ) {
//---抓名子---
_ball = new Ball();
_ball.frName_txt.text = _vector[i].name + "";
_ball.frName_txt.autoSize=TextFieldAutoSize.CENTER;
_ball.x = _sw/2;
_ball.y = _sh/2;
_ballContaner.addChild(_ball);
}
}
function onCompleteHandler(e:Event):void {
_i += 1;
var rr:Number = _agrUtil * _i;
var LL:Loader = LoaderInfo(e.currentTarget).loader;
LL.width = 180;
LL.height = 180;
LL.x = LL.width / 2 * -1;
LL.y = LL.height / 2 * -1;
_card = new CardMc();
_card.name = "cardItem"+_i;
_card.x = 0;
_card.y = 0;
_card.addChild(LL);
_card.scaleX = _card.scaleY = 0.5;
TweenMax.to(_card, .5, { x:Math.cos(rr)*_radius,y:Math.sin(rr)*_radius,delay: 0.5+_i*0.1,ease:Back.easeInOut} )
_contaner.addChild(_card);
if (_i == _num) onTimerStartEvent();
}
function onTimerStartEvent():void {
TweenMax.to(_loading, .5, { alpha:0 } );
removeChild(_loading);
_timerA.addEventListener(TimerEvent.TIMER, onTimerAEventHandler);
_timerA.start();
}
function onTimerAEventHandler(e:TimerEvent):void {
//trace("ttt")
_contaner.addEventListener(Event.ENTER_FRAME, onRotaion);
for (var i:int = 0; i < _num; i++) {
var mm:MovieClip = _contaner.getChildAt(i) as MovieClip;
mm.addEventListener(Event.ENTER_FRAME, onRotaionCard);
}
_timerA.removeEventListener(TimerEvent.TIMER, onTimerAEventHandler);
_timerB.addEventListener(TimerEvent.TIMER, onTimerBEventHandler);
_timerB.start();
}
function onTimerBEventHandler(e:TimerEvent):void {
for (var i:int = 0; i < _num; i++) {
var mm:MovieClip = _contaner.getChildAt(i) as MovieClip;
TweenMax.to(mm, .5, { x:0,y:0,delay: 0.5+i*0.1,ease:Back.easeInOut} )
}
_timerB.removeEventListener(TimerEvent.TIMER, onTimerBEventHandler);
_timerC.addEventListener(TimerEvent.TIMER, onTimerCEventHandler);
_timerC.start();
}
function onTimerCEventHandler(e:TimerEvent):void {
var $tarX:Number = -300;
//trace("$tarX----------",$tarX)
var $tarY:Number = 100;
TweenMax.to(_contaner,.5,{x:_centerX,y:_centerY})
_contaner.removeEventListener(Event.ENTER_FRAME, onRotaion);
for (var K:int = 0; K < _num; K++) {
var mm:MovieClip = _contaner.getChildAt(K) as MovieClip;
//mm.removeEventListener(Event.ENTER_FRAME, onRotaionCard);
TweenMax.to(mm, .5, { rotationX:0,rotationY:0 } );
}
_contaner.rotationX=0
_contaner.rotationY=0
for (var j:int = 1; j <= 2; j++ ) {
for (var i:int = 1; i <= 13; i++ ) {
if(j%2==0){
if(i%2!=0) continue;
}else{
if(i%2==0) continue;
}
//trace(j,"---------j")
trace(i,"---------i")
var mm2:MovieClip =_contaner.getChildAt(i-1) as MovieClip;
TweenMax.to(mm2, .5, { x:($tarX + (i-1)*50), y:$tarY * j ,scaleX:0.2,scaleY:0.2, delay: 0.5 + i * 0.1, ease:Back.easeInOut } )
}
}
_timerC.removeEventListener(TimerEvent.TIMER, onTimerCEventHandler);
TweenMax.to(_ballContaner, .5, { alpha:0, transformAroundCenter: { scaleX:2, scaleY:2 }, ease:Back.easeInOut, onComplete:function():void {
this.removeChildAt(_ballContaner, 0);
}})
_timerD.addEventListener(TimerEvent.TIMER, onTimerDEventHandler);
_timerD.start();
}
function onTimerDEventHandler(e:TimerEvent):void {
var $tmp:int = 0;
for (var i:int = 0; i < _num; i++) {
var mm:MovieClip = _contaner.getChildAt(i) as MovieClip;
TweenMax.to(mm, .5, { x:0, y:0, scaleX:0.2 + 0.07 * i, scaleY:0.2 + 0.07 * i, delay: 0.5 + i * 0.1, ease:Back.easeInOut, onComplete:function():void {
$tmp += 1;
if ($tmp == 13) {
addChild(_smokerMc);
_smokerMc.play();
removeChild(_contaner);
TweenMax.to(_rayCard,.3,{alpha:1,transformAroundCenter:{scaleX:1, scaleY:1},ease:Back.easeInOut})
TweenMax.to(_loader2, .3, { alpha:1, transformAroundCenter: { scaleX:1, scaleY:1 }, ease:Back.easeInOut, onComplete:function():void {
TweenMax.to(_loader2, .5, { alpha:0, transformAroundCenter: { scaleX:2, scaleY:2 }, delay:2, ease:Back.easeInOut } )
_timerE.addEventListener(TimerEvent.TIMER, onTimerEEventHandler);
_timerE.start();
}})
}
}} )
mm.addEventListener(Event.ENTER_FRAME, onRotaionCard);
}
_timerD.removeEventListener(TimerEvent.TIMER, onTimerDEventHandler);
}
function onTimerEEventHandler(e:TimerEvent):void {
trace("火");
removeChild(_smokerMc);
_rayContaner = new Sprite();
addChild(_rayContaner);
var $effect:BlazingEffect = new BlazingEffect(_rayContaner, _rayCard);
$effect.addEventListener(BlazingEffect.EFFECT_COMPLETE, onEffectCompleteHandler);
_timerE.removeEventListener(TimerEvent.TIMER, onTimerEEventHandler);
}
function onEffectCompleteHandler(e:Event):void {
trace("Over")
var bn:ShereFB = new ShereFB();
addChild(bn);
bn.buttonMode = true;
bn.addEventListener(MouseEvent.CLICK, onMouseClickHandler);
bn.x = _sw/2;
bn.y = _sh/2;
TweenMax.from(bn, .5, { scaleX:2, scaleY:2,alpha:0 } );
}
function onMouseClickHandler(e:MouseEvent):void {
var mess:Message = new Message("facebook_API測試" + fb.uid);
mess.picture = "http://www.rainmaker96.com.tw/fb_test/card.jpg";
mess.message = "Ray的faceBook-API測試";
mess.link = "http://www.rainmaker96.com.tw/fb_test/bin/";
mess.name = "鳥站";
mess.caption = "表題:Ray的facebook-api測試";
mess.description = "猜猜我能不能抓到你的好友圖片";
fb.papaPost(mess);
}
function onRotaion(e:Event):void {
_contaner.rotationY = _contaner.rotationY % 360;
_contaner.rotationX = _contaner.rotationX % 360;
_contaner.rotationY += (_centerX - stage.mouseY) / 30;
_contaner.rotationX += (_centerY - stage.mouseX) / 30;
//_contaner.rotationY = 360;
//trace("rotaionX-------",_contaner.rotationX)
//_card.rotationZ += (_center - stage.mouseX) / 20;
}
function onRotaionCard(e:Event):void {
e.currentTarget.rotationX -= (_centerX - stage.mouseX) / 50;
e.currentTarget.rotationY -= (_centerY - stage.mouseY) / 50;
}
※ 引述《bettyHo (betty)》之銘言:
: 如題
: 因為設計一個APP
: 希望user用FB帳號 login
: 再分享照片到FB
: 請問相關的程式碼要怎麼寫
: 我要全部寫成一個工作檔
: 有找到相關的
: 但看不大懂
: 懇求各位大大賜予小女指點迷津吧!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 119.14.48.233
※ 文章網址: http://www.ptt.cc/bbs/Flash/M.1402457375.A.F90.html
→
06/12 10:50, , 1F
06/12 10:50, 1F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Flash 近期熱門文章
PTT數位生活區 即時熱門文章