Flash Documentation

From J2Play

Jump to: navigation, search

Contents

Overview

This tutorial explains how to add J2Play features to Adobe Flash games. A word document version is available: Media:J2Play_5_Minute_Flash_Integration_Tutorial.doc

Prerequisites

  • Familiarity with Adobe Flash 6, 7, 8 or 9
  • Some ActionScript 2.0 or 3.0 knowledge

Download the J2Play Flash Toolkit

J2Play Toolkit for Flash: Image:J2play-flash-toolkit.zip

Extracting the J2Play Flash Toolkit will create one of the following directories:

j2play-flash-toolkit/flash6 - Use this for Flash 6, ActionScript version 2.
j2play-flash-toolkit/as2 - Use this for Flash 7-9, ActionScript version 2.
j2play-flash-toolkit/as3 - Use this for Flash 9, ActionScript version 3.

Integration

There are two ways to integrate your game with the J2Play Flash library.

1) J2Play Flash Wrapper:

The first and easiest method uses the j2play-flash as a wrapper to load the J2Play library and your game .swf file.

2) Flash Library Integration:

Loading j2playlib inside your game flash, and adding code to init it yourself.

There are some clues to help you decide which is right for you.

  • If you don't know anything about ActionScript, using 1)
  • If your game contains more than one flash movie or more than one scene, and one of them is the loader for others, using 1) and set the loader swf as your game swf in game.properties
  • If you uses _root or Stage as a base to access the objects in your flash, you have to use 2)
  • If you want to control the time of initialization and loading, you should choose 2)

Please follow the integration guide (J2Play Flash Wrapper or Flash Library Integration) you choose and finish the integration and testing.

Publish

Congratulations, you have created a social game! Publish it on all social sites using the J2Play Game Management System.

If you haven't done so already, Setup your game on the J2Play Game Management System.

Now, from the main page:

  1. Click the "Edit" button for your game.
  2. Select a social site (e.g., Facebook, Myspace, etc.) from the "Network" drop down.
  3. Click the "Add" button.
  4. Click the "Instructions" link.
  5. Follow the instructions to add your game to the social site you selected.

ActionScript

This section tells you what facilities J2Play Library provide and how you use them.

J2Play Controller

The J2PlayController is the main interface class of J2Play library, and is accessible in your Flash game as the following:

ActionScript 2

import ca.j2x.flash.IController;

var j2play:IController = _global.controller;

ActionScript 3

import ca.j2x.flash.IController;
import ca.j2x.flash.lang.Global;

var j2play:IController = Global.vars.controller;

Basic interface

J2PlayController provides following APIs for basic information about J2Play environment.

For a full interface description of the controller, look at j2play-flash-toolkit/[flash version]/interfaces/ca/j2x/flash/IController.as

Leaderboards

J2Play leader boards list and store the best scores of a game.

Acquire the score interface

To use the leader board feature, start by acquiring a reference to the score interface:

ActionScript 2

import ca.j2x.flash.IScore;
import ca.j2x.flash.IController;

var j2play:IController = _global.controller;
var score: IScore = j2play.getScore();

ActionScript 3

import ca.j2x.flash.lang.Global;
import ca.j2x.flash.IScore;
import ca.j2x.flash.IController;

var j2play:IController = Global.vars.controller;
var score: IScore = j2play.getScore();

Easy way to set/get score

If the score is accumulative and every player only has one record in the Leader Board. You can use easySetScore/easyGetScore to manage it easily.

More flexible way to set/get score

This pair of methods are very flexible and provide the full range of options.

Challenges

Player can challenge his friends or other players with a game. The challenge system will launch a game for challenger, after challenger finishes his move, challenger system will send the challenge inviation to all players challenger selected. And if receiver accept the challenge, the challenger system will launch the game for receiver; other wise game will be closed.

Is the game a challenge

Firstly, use J2PlayController.isChallenge() to decide a game is a solo game or a challenge game.

Acquire the challenge interface

You can access all challenge information through interface ca.j2x.flash.IChallenge. If the game is challenge, then you can get challenge interface through _global.controller.getChallenge()

import ca.j2x.flash.IChallenge;
var challenge: IChallenge = _global.controller.getChallenge();

Update at beginning of player's turn

At the beginning of each player's turn, you should call Challenge.updateGamePlay() to notify Challenge System game that current player start to play.

Update at the end of player's turn

After a player finish his move, this turn ends.

  1. Use Challenge.setDisplayMessage() to set the message for next player, like "Score to beat: 2000" or "Turn: 2";
  2. And call Challenge.updateNextTurn(), which commits the message you set with Challenge.setPlayerInfoString(), and then notify the challenge system to let next player start his turn. If current player has finished his game, and will not move anymore, you should set var finish=true.

Update at the end of game

When everyone finish his move, and game has a result, you need to

  1. Use Challenge.setDisplayMessage() or Challenge.setDisplayMessages() to set the message of result, like "You win $5000", "You lost $5000" or "You beat xxx by 5000 high scores";
  2. And use Challenge.setResult() to set game result: who win, who lose.
  3. There are two way to commit the message and report the game end to challenge system:
    1. call Challenge.updateNextTurn() with var finish=true for the case that every player did that already. When all of players in the challenge finish his game, the game will be finished automatically.
    2. call Challenge.updateGameEnd() in case the game is ended by current player's move.

Other function for challenge information

You can access all the challenge information through interface ca.j2x.flash.IChallenge.

You can make your game work with the challenge system according to this Challenge Toturial

Interaction with J2Play Playground

Playground class includes the APIs for controlling the J2Play playground.

Importing Playground class into your code at the top of the ActionScript file

import ca.j2x.flash.Playground;

Tab Switch

Switch the J2Play playground tab from the Play tab where your game is shown up to other tab like Challenges or Achievements

Switching to Home Tab

Use Playground.switchToHomeTab() switch to Home tab

Switching to Challenges Tab

Use Playground.switchToChallengeTab() switch to the Challenge Center sub-tab in Challenges tab

Switching to Leaderboards Tab

Use Playground.switchToLeaderBoardTab() switch to the LeaderBoards sub-tab in Achievements tab

Switching to Store Tab

Use Playground.switchToStoreTab() switch to Store tab

Notification & Feed

The Notifications API enables you to send different types of notifications, mini-feed stories, news stories, and invites to the external social networking site. This feature will handle sending the message specifically to the social networking site if available.

Notification

Using Playground.sendNotification() to send a notification message to another user.

Feed

Using Playground.publishActivityFeed() to publish a feed for your activity.

Invites

Profiles

Through the profile API, public information about players can be obtained. Use the following interface:

Actionscript 2

import ca.j2x.flash.IRemoteProfile;
import ca.j2x.flash.IController;

var j2play:IController = _global.controller;
var profile:IRemoteProfile = j2play.getRemoteProfile();

Actionscript 3

import ca.j2x.flash.lang.Global;
import ca.j2x.flash.IController;
import ca.j2x.flash.IRemoteProfile;

var j2play:IController = Global.vars.controller;
var profile:IRemoteProfile = j2play.getRemoteProfile();

The following remote profile methods provide access to profile images:

Saving/Loading

The Saving and Loading API's lets you save and restore the state of your game so players progress is always maintained.

Saving

Loading

Friends List

The Friends List API allows give you access to the players friends list so you can retrieve the users friends and create interesting social games.

Get the BuddyList interface by following way, and use it to manipulate buddies

import ca.j2x.flash.IController;
import ca.j2x.flash.IBuddyList;
var buddylist : IBuddyList = controller.getBuddyList();

The BuddyList interface provides the following methods:

Badges

BETA

contact developer@j2play.net before using this feature for technical support

Defining Badges

The Badge admin interface is being reworked to simplify the process more please contact developer@j2play.net if you want to add badges to your game until we get the new and improved Badge Admin released shortly.

Badges are defined as follows:

  1. badgeID - badgeID: number; // define the type of a badge
  2. badgeProperties - badgeProperties: ca.j2x.flash.util.Map; // define the properties of a badge

Every property in badgeProperties is a key / value pair (id=>value)

id: Number; // identification of badge argument
value: String; // the value of specific badge argument

The following method notifies the platform when the player acquires a badge:

Credits

BETA

contact developer@j2play.net before using this feature for technical support

Loyalty credits define a point and currency system in one. Users gain points from game achievements or purchase, and can spend them on other games or items.

Loyalty point is part of RemoteProfile, see Profiles for how to get the profile interface.

Use following methods to get and adjust loyalty point value of specified user:

Multiplayer

ALPHA

Contact developer@j2play.net to be one of the first developers to use this feature!

Join2play (J2Play's multi-player system) is temporarily unavailable in the Flash platform.

Tournaments

ALPHA

Contact developer@j2play.net to be one of the first developers to use this feature!

Tournaments are temporarily unavailable in the Flash platform.

Store

ALPHA

Contact developer@j2play.net to be one of the first developers to use this feature!

Personal tools