Web Requests

by Jon (Updated on 2015-10-18)


  • Visiting a URL
  • HTTP Requests
  • Example: Loading levels from a server
  • Accessing Flash variables
  • Launching Apps on Mobile using URLs
  • Frequently Asked Questions

Visiting a URL

Using the open URL block (under Game > Web), you can visit any URL from within a game. The link will open up inside a new tab, using the user's default browser. On Flash/Desktop, a pop-up blocker can prevent this from happening.

Open URL block

Tip: If you want an in-app browser, check out the Web Views extension.

What could you use this for?

  • Visiting Social Media (Facebook, Twitter)
  • Asking for a Paypal donation
  • Linking to your mobile game’s entry

Note: We have pre-built behaviors for the first 2 scenarios. Check them out under the “Utilities” category the next time you import a behavior for a scene.

HTTP Requests (GET / POST)

What if you want your game to communicate with a web-based API? Stencyl also supports making HTTP requests, so that your game can communicate with REST-based APIs and can submit data to scripts that you've built yourself.

How to make an HTTP Request

Make an HTTP request using either the visit URL block or POST data block (both under Game > Web). The first block corresponds to a GET request, while the second corresponds to a POST request.

HTTP request blocks

Either way, calls are asynchronous (non-blocking). We callback by executing the body of the blocks when you receive a response, which can be fetched using the red site's response block.

If the HTTP request fails, no callback will be issued. We recommend using a timeout (via a do-after block, for example) to handle the case of failure.

Multiple Field POST Requests

If you're trying to submit data, a POST request is the preferred method for doing that. What if you want to submit multiple pieces of data?

You can pass in multiple fields at once by separating them with ampersands (&), like this:


Example: Loading Levels from a Server

In an early Stencyl game that featured a level editor, the developer used HTTP requests to implement a level sharing system. We'll now step through a simplified example of this.

Suppose that we’re building a simple game that stores its levels online. We want to create a level loader for this game that takes the data and creates actors based on the type and location.

Here's some sample data: http://dl.dropbox.com/u/2769678/level1.txt

This file contains just 3 entries, one line each. The 3 "columns" correspond to: Name of the actor, x-location, y-location.


Here’s how we could parse this. We tokenize ech line one by one, knowing that each entry is separated by commas.


If you're building your own web services to communicate with Stencyl, keep your data formats simple, and you can achieve pretty cool things with web requests.

Launching Apps on Mobile using URLs


Opens the Facebook app to the page you define. Useful for directing users to your Facebook page, so they can "Like" it without having to use the official API.

fb://profile/[your ID]


Opens Twitter app to the page you define. For example, you could open it up to the page for your game/studio to encourage a "Follow" without having to use the official API.


See this forum topic for more examples.

Frequently Asked Questions

Does Stencyl provide XML / JSON parsing out of the box?

Many API's provide responses in standard formats such as XML or JSON. Parsing XML and JSON-based responses is not handled by Stencyl out of the box (in the sense that our blocks support it), but it is supported in code via Haxe.

Can Stencyl communicate directly with a database?

No. For security reasons, it is not best practice to allow a game to directly query a database. Instead, write a script on your server that Stencyl can communicate with using HTTP requests.

If I'm making a mobile game, can I show the page inside the app, instead of launching Safari / Chrome?

If you want an in-app browser, check out the Web Views extension.


  • Visit URLs to point players to your social media pages, Paypal page or iOS game entry.
  • HTTP requests let you do just about anything. The “Populate” game for Flash and iOS uses HTTP requests to implement a level share system.
  • Flash variables can be used to communicate with a Flash game's containing webpage.
Print Article Edit Article How to Edit an Article
Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!


The answer to that question is beyond the scope of Stencyl and doesn't require anything beyond the HTTP requests we provide. Because we get the question, I'll answer it here briefly.

Build a script in any language of your choice (PHP, Python, etc.), pass in the variables via GET/POST and have the script query the database. Stencyl cannot and should never be expected to interact directly with a database.

0 1 month, 2 weeks ago
why is no one able to answer how to send SCORE to PHP/DATABASE?
0 2 months, 1 day ago
How can I save game attributes to a server? I have set up a php file accessing a mysql database, and I also have a crossdomain file allowing access between websites.
1 11 months, 3 weeks ago
how can I upload the highscore of the player in my server, and after, load a list of the top 10 best scores and show on game?
0 1 year, 3 months ago
Does anyone know how viable this is in a popular flash game? If a game got, say, millions of views, would you need a really good server if your game was constantly using web requests?
1 3 years, 6 months ago
Added a blurb about accessing Flash variables from a forum user: http://community.stencyl.com/index. php/topic,8326.0.html
0 3 years, 7 months ago
@chris - Rhys developed his own format and hosted it on his own server.

@greyman - Yep, that's a good point. I'll note it.

0 3 years, 7 months ago
What did Populate use for their level editor? any specific platform?
0 3 years, 7 months ago
Nice one, the in app browser is a great idea, look forward to it.

I also found that you can POST multiple pairs of data if you put it in the form:

Now just need to work on Cookie handling and submitting....

0 3 years, 8 months ago

Sign In to Comment