Developer / Documentation / How to create a flash application

This article describes working with the custom Netlog REST API which is depricated.

Instead, please use our OpenSocial implementation instead, using our OpenSocial REST API directly or, for example this OpenSocial PHP client which takes care of the authentication for you.

If you'd still like to use this API, please get in touch first.

Introduction

This tutorial describes how you can create your own flash application. We will make a simple demo application called demoApplication that you can use as a template for creating your own applications.
The demoApplication is written in Actionscript 3.0 and uses these client components (version 1.0.3).

This tutorial will first give a short overview of some important concepts before going into detail about how to make an application.

Application ID and Application Key

In order to identify the different applications, you need to acquire an Application ID and Application Key. The first one is for identifying your application while the latter one is used for securing your API calls (see further) and should be kept strictly private.
For the moment, these ID's and Key's can only be recquired through Netlog.

Building your application

Start by downloading the client components. This file contains an MXP installer together with some documentation about the components and their methods. You can install the mxp file with the Adobe Extension Manager. Afterwards, the components are available through the component window in the Flash IDE. There are 2 components: NetlogClient and NetlogEvent. The first one contains functions to call all API methods that are currently available. NetlogEvent is an eventclass that handles the calling of the API server and returning the result. When API calls are made and results or errors are returned, listen for these events as they will contain the appropriate information.

When creating your application, you start by creating a document class, for instance : DemoApp. Attach it to the document class of your fla and paste the following code inside:

package com.netlog.demo {
 import flash.display.*;
 import com.netlog.api.*;
 
public class DemoApp extends MovieClip { private var mAppKey:String = "DemoKey"; private var mServerAdress:String = "http://apiserver"; private var mVersion:String = "1.0"; private var mTicket:String = "DemoTicket"; private var mLanguage:String = "DemoLanguage"; private var mConnectionClient:NetlogClient;
public function DemoApp() { // Create the client mConnectionClient = new NetlogClient(mAppKey, mTicket, mServerAdress, mLanguage); // Add listeners mConnectionClient.addEventListener(NetlogEvent.RESULT_GETLOGGEDINUSER, onResponseHandler); mConnectionClient.addEventListener(NetlogEvent.ERROR, onError); mConnectionClient.addEventListener(NetlogEvent.PAGE_LOADED, initialize); // Set traceoutput, so we get some information along the way mConnectionClient.traceoutput = true; }
public function initialize(e:NetlogEvent) { // Try to get the current logged in user's id mConnectionClient.getLoggedInUser(); }
public function onResponseHandler(e:NetlogEvent) { for (var name:String in e.data) { trace ("-> " + name + " : " + e.data[name]); } }
public function onError(e:NetlogEvent) { for (var name:String in e.data) { trace ("-> " + name + " : " + e.data[name]); } } } }

There are 4 parameters that are needed for operation, these are as follows:
( Be sure to notice that the important parameters for the API here are just dummies. )

  • Application Key (mAppKey:String) : as stated above, the key should be hardcoded and kept private.
  • Server Adress (mServerAdress:String) : the location of the Netlog API, provided by Netlog.
  • Ticket (mTicket:String) : a unique ticket is needed to make an API call, this is usually provided externally through flashvars.
  • Language (mLanguage:String) : the language of the distribution the application is on

When you set the traceoutput property, the client will output some useful information in the tracepanel. By default, it behaves silent as to not interfere with your own tracestack.

This little example will get the ID from the currently logged in user and output it in a trace in the onResponseHandler method. Any errors will be handled or outputted by the onError method. This is the basics to event-handling with the API.