1

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]
Ant
  • 77
  • 2
  • 10
  • all you need to do it when the player enters their name, just hold the value somewhere; be it an object, a static variable, a local shared object etc. It's no different from holding any other piece of information. instead of dispatching an event in `SubmitClicked`, store `NameTextField.text` in a variable, and use that variable in your `navigateToURL` code – divillysausages Apr 09 '12 at 14:00

2 Answers2

2

In order to post to twitter you need to be authenticated.

I suggest you use an existing api like Tweetr by swfjunkie_com or Twitter-ActionScript-API by Denis Borisenko

Check this post for a sample code and for more details

http://www.redcodelabs.com/2012/02/actionscript3-twitter-api/

Adrian Pirvulescu
  • 4,308
  • 3
  • 30
  • 47
  • Have already got AS3 posting to Twitter both the name and time. The problem is posting them together when the name is entered in the main menu and the time is entered in the game. – Ant Apr 08 '12 at 16:02
0

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; }

Kamal
  • 1,122
  • 11
  • 18
  • Hey Sorry is all in AS3 don't have any JS knowledge. Not sure if any of this works with JS ? – Ant Apr 08 '12 at 15:59
  • you don't need much JS knowledge for this.. just declare a variable like i did.. and assign your name to that variable.. and create one function 'function getName() return nameVariable; ' and call it from AS3 – Kamal Apr 08 '12 at 16:01
  • Sorry confused the code above all goes into flash? var TextFieldName = "InputName"; and on the continue button I'd put: ExternalInterface.call('InputName'); ?? – Ant Apr 08 '12 at 17:35