A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Posting from AS3 to Twitter

  1. #1
    Member
    Join Date
    Apr 2011
    Posts
    42

    Posting from AS3 to Twitter

    Hey all,

    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 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');

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Is there a question? Are you receiving errors? What are they? Did you read them?

    The problem is probably that you are getting something like "undefined property NameTextField". And that is because there is no property called NameTextField. And that is because NameTextField is a child of your menu, not your game.
    You need to save the name entered in the menu somewhere accessible to the game. Then use that saved value.

    It's a bad idea to use textfields as the actual places to store your information. TextFields are just UI. The UI should reflect the abstract state of your models (game, menu, other classes). That is, store the name in a String variable, and the time in another variable (probably Number which stores the number of milliseconds). Use those variables to drive the UI.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center