views:

607

answers:

1

Hi, everyone.

I think you can help me out from this little problem.

I am a novice in Facebook developer by choosing ActionScript 3 as my developer platform. I use SWC library from official facebook-actionscript-api that promoted by Adobe.

So I followed their tutorial. So I did following instruction:

  1. Create Flex project.
  2. Download and put Facebook_library_v3.4_flex.swc to \lib in Flex project.
  3. Provide following code:

            import com.facebook.Facebook;
            import com.facebook.utils.FacebookSessionUtil;
    
    
    
        private var fbook:Facebook;
        private var session: FacebookSessionUtil;
    
    
        protected var api_key : String = "my-facebook-app-api-key";
        protected var secret_key : String = "my-facebook-app-secret-key";
    
    
        public function init() : void {
            //fbook = new Facebook();
            session=new FacebookSessionUtil(api_key,secret_key,this.loaderInfo);
            var fbook : Facebook = session.facebook;
            session.validateLogin();
        }
    

    After trying to run debug session. I got the error after execute this statement:

    session=new FacebookSessionUtil(api_key,secret_key,this.loaderInfo);

I think I did something wrong but I couldn't figure it out. Could you help me by giving your advice or any guideline?

This is exception I got:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.facebook.utils::FacebookSessionUtil()[C:\Users\MikeHunt\Work\FacebookAPI\src\com\facebook\utils\FacebookSessionUtil.as:128]
at CheeseZaa/init()[/Users/teerasej/Documents/Flex Builder 3?/freelance/CheeseZaa/src/CheeseZaa.mxml:24]
at CheeseZaa/___CheeseZaa_Application1_creationComplete()[/Users/teerasej/Documents/Flex Builder 3?/freelance/CheeseZaa/src/CheeseZaa.mxml:4]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9440]
at mx.core::UIComponent/set initialized()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1168]
at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8744]
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8684]

I notice that the first line of exception show this:

com.facebook.utils::FacebookSessionUtil()[C:\Users\MikeHunt\Work\FacebookAPI\src\com\facebook\utils\FacebookSessionUtil.as:128]

But I don't sure it involve in exception.

My development platform is:

  • Macbook Pro
  • OSX Snow Leopard 10.6
  • Flash Player 10.0.32 Debugger
  • Mozilla Firefox 3.6
  • Flex builder 3.2
  • Flex SDK 3.5
  • Facebook_library_v3.4_flex.swc

Every suggestion and guideline would be thank you. I think this would be good for other developer that may found the same problem like me.

A: 

loaderInfo is not ready and is currently null.

try:-

public function init():void
{
    addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
}

private function onAddedToStage(event:Event):void
{
    removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

    session = new FacebookSessionUtil(api_key, secret_key, this.loaderInfo);
    var fbook:Facebook = session.facebook;

    session.validateLogin();
}
soul
Thank you, soul! your solution works like a charm! I wonder why there is so less developer found this problem. Actually, I never found it before, even in Windows.
Teerasej