Search code examples
actionscript-3flashfla

Posting from AS3 to Twitter


I've got a main menu and a game which loads as a separate swf from that menu. So far when the player enters their name at the start on the main menu I can get this name to post to Twitter. Also when the player completes the game I get post their time onto Twitter.

The problem is that I want to take the name posted from the main menu and dispatch it and only when the player completed the game post their time and name to Twitter.

Code in main menu to dispatch name:

[CODE]
var NameTextField:TextField = new TextField();
var MyFormat:TextFormat = new TextFormat();

addChild(NameTextField);


SubmitButton.addEventListener(MouseEvent.CLICK, SubmitClicked);


function SubmitClicked(e:MouseEvent)
{
    dispatchEvent(new Event(NameTextField.text, true));
    trace (NameTextField.text);
    NameTextField.selectable = false;
}
[/CODE]

Code in game to receive name and post time to twitter.

[CODE]
navigateToURL(new URLRequest('http://twitter.com/home?status='+encodeURIComponent(+NameTextField.text+" completed Game"+' in a time of '+HourText.text+':'+MinuteText.text+':'+SecondText.text+'')),'_blank');
[/CODE]

Solution

  • I assume you have twitter authentication already taken care of..

    So when user enters the name on main menu you can save the name into save global variable in javascript like

    var name = "some name";
    

    and call ExternalInterface from as3 when user is done playing
    like

    ExternalInterface.call('getName'..
    

    in js you should have a function like

    function getName() { return name; }