Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
Level: Beginner

Web Requests

Contents

  • Visiting a URL
  • HTTP Requests
  • Example: Loading levels from a server
  • Accessing Flash variables


Visiting a URL

Did you know that you could visit URLs from within a game? It’s as easy as using this block under Game > Web. The link will open up in your default browser inside a new tab.


What could you use this for?

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


Incidentally, we have pre-built behaviors for the first 2 - check them out under the “Utilities” category the next time you import a behavior for a scene.

Note: On mobile platforms, the default browser app will display. We’re working on an integrated in-app browser solution instead.

 

Note: Some pop-up blockers may prevent your game from opening a new tab.

 

HTTP Requests (GET / POST)

Your game can make HTTP GET and POST requests to remote sites and servers. This is great for fetching data from REST-based APIs or submitting new data.

Calls are asynchronous (non-blocking), and we callback by executing the body of the blocks when you receive a response.

Like the visit URL block, these are found under Game > Web.

Note: For POST requests, you can pass in multiple fields at once by separating them with ampersands (&), like this:

name=John&id=123456

In Populate, the developer used HTTP requests to implement a level sharing system.

Parsing XML and JSON-based responses is beyond the scope of this article, but check out our example, which uses HTTP GET to load in simple data from a remote server.

 

Example: Loading Levels from a Server

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. Name of the actor and then x,y location. Pretty simple.

robot,0,0
robot,128,128
hero,256,256

Here’s how we could parse this.

Moral of the story is this: keep your data formats simple, and you can achieve pretty cool things with web requests.

 

Accessing Flash Variables

Not only does Stencyl let you access data from remote sites, but using Flash variables, you can also access data from a Flash game's containing webpage. The following AS3 code snippet can be used in a Code block or a Code Mode Behavior to achieve this:

var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(FlxG.stage.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
   print(keyStr);
   print(valueStr);
}

Summary

  • 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.


Last Updated: 2013-04-02 by Joe

8597 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game, please ask a question on the forums. Thanks!
5 Comments
Weasel8778
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?
0 11 months, 3 weeks ago
Joe
Added a blurb about accessing Flash variables from a forum user: http://community.stencyl.com/index. php/topic,8326.0.html
0 1 year, 1 month ago
Jon
@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 1 year, 1 month ago
kinifi
What did Populate use for their level editor? any specific platform?
0 1 year, 1 month ago
Greyman22
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:
name=John;id=123456

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

0 1 year, 1 month ago



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.