Be a Supporter!

Re-connecting The Api [as3]

  • 372 Views
  • 1 Reply
New Topic Respond to this Topic
Zanzlanz
Zanzlanz
  • Member since: Sep. 9, 2011
  • Offline.
Forum Stats
Supporter
Level 15
Game Developer
Re-connecting The Api [as3] 2012-05-15 19:36:24 Reply

Hello there!

I want to make a simple script that, if the connection fails when connecting to the Newgrounds's API, it will simply try again when it times out.
The problem I'm having, is that I can't get it to try again (when it fails) without spamming me errors such as "The Newgrounds API is already disconnected." and "The Newgrounds API is already connected."

Here's the main code that should have worked.

import com.newgrounds.*;
API.connect(root, "742834:898d7ddddd", "sdf8sdf08sdf890sdfdfd9d9999999d9dd");
API.addEventListener(APIEvent.API_CONNECTED, onAPIConnected);

function onAPIConnected(event:APIEvent):void {
	if (! event.success) {
		//API.disconnect();  
		API.connect(root, "742834:898d7ddddd", "sdf8sdf08sdf890sdfdfd9d9999999d9dd");
	}
}

API.disconnect shouldn't be necessary, since it's already disconnected. But without it, it tells me over and over again, that it's already connected (Which it isn't). But when I add API.disconnect, it tells me it's already disconnected, and stops the code from trying to reconnect.

Can you see where my dilemma is?
I'll keep trying, but if any of you guys have tried doing this before, and have a simple code you can share with me to accomplish my simple task, please help :)

Just for reference:
http://www.newgrounds.com/wiki/creator-resources/flash-api/c onnecting-to-the-api

- Zanzlanz


http://www.newgrounds.com/portal/vi ew/579172
Yes, that's Minecraft in Flash :3

Zanzlanz
Zanzlanz
  • Member since: Sep. 9, 2011
  • Offline.
Forum Stats
Supporter
Level 15
Game Developer
Response to Re-connecting The Api [as3] 2012-05-16 16:44:22 Reply

Erm... is this even possible? Anyone?


http://www.newgrounds.com/portal/vi ew/579172
Yes, that's Minecraft in Flash :3