TechTip: Connect ActionScript 3.0 with IBM i to Enable Flash Programs

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

It's true! You can allow Flash programs to work with IBM i via the IBM i host servers.


Adobe Flash (formerly SmartSketch FutureSplash, FutureSplash Animator, and Macromedia Flash) is a multimedia platform used to add animation, video, and interactivity to Web pages. Flash is frequently used for advertisements, games, and animations for broadcast. More recently, it has been positioned as a tool for the development of cross-platform Rich Internet Applications (RIAs).


ActionScript 3.0 (also referred to AS3), a full-featured object-oriented programming language, is the core language of Adobe Flash. Flash programs can run in Adobe Flash Player, which is a Web browser plug-in, in a standalone Flash Player, or as desktop programs with the support of the cross-platform Adobe Integrated Runtime (AIR) runtime environment. Notable Web applications using Flash include Yahoo! Web Messenger and Sherwin-Williams' Color Visualizer.


So, what can we do by connecting Adobe Flash with the platform we work on every day, the IBM i?


1. With Adobe Flash, we can construct IBM i-backed cross-platform applications (either RIAs or desktop applications).

2. Numerous systems and devices can be allowed to connect to IBM i. The Adobe Flash Player exists for a variety of systems and devices: Windows, Mac OS 9/X, Linux, Solaris, HP-UX, Pocket PC/Windows CE, OS/2, QNX, Android, Symbian, Palm OS, BeOS, and IRIX.

3. IBM i-backed applications can take advantage of the extremely strong support provided by Flash for user interfaces and multimedia.

4. Best of all, perhaps we can attract existing Flash developers and users to the very versatile and easy-to-use IBM i platform.

Accessing IBM i from Flash Programs via the IBM i Host Servers

Now comes the next question: how to connect Adobe Flash with IBM i. The solution is to access IBM i from Flash programs via the IBM i host servers. The benefits are the following:


1. For a client program, accessing IBM i via the IBM i host servers is the most direct and efficient way. The IBM i host servers are TCP servers, so clients communicate with the host servers directly at the TCP layer.


2. The IBM i host servers allow client programs to access various resources and consume business logic available on an IBM i server in quite a range of flexible ways. For example, the Remote Command and Distributed Program Call Server allows clients to issue CL commands or call programs on an IBM i server; the DRDA/DDM Server supports record-level access to database files; the File Server allows clients to access IFS resources. In addition, with the program call support, the client can call various kinds of APIs. This further improves the flexibility of the client.


3. Accessing IBM i via the IBM i host servers does not require additional server-side development and deployment.

The Open-Source Project as-400

A subproject of the open-source project i5/OS Programmer's Toolkit has just been launched. It's called as-400 (aka "ActionScript and AS/400"). The as-400 subproject is aimed at implementing an AS3 class library (.swc file) that can be reused by other Flash applications to consume services exposed by the IBM i host servers. Just like the IBM Toolbox for Java and its open-source version, JTOpen, which connects Java clients to IBM i, as-400 will connect Flash clients to IBM i.

Hello, IBM i!

This section will show you a simple but meaningful example of accessing IBM i from a Flash program. We'll call IBM i programs from a Flash program via the Remote Command and Distributed Program Call Server.


The following is a screenshot of Flash program t007.swf, which is compiled from AS3 source file



Figure 1: Let's start here.


This Flash program allows browser users to put a queue message onto a User Queue (USRQ) object (QGPL/Q007) on an IBM i server. When the apple is clicked, the following event-handler method is invoked and calls the Queue Object API ENQ to queue up the user-entered message onto QGPL/Q007.


        private function onBtnClick(evt:MouseEvent) : void {


            var pgm_call:RemoteCommand =

                new RemoteCommand(i_host.text,




                                  "ENQ");  // [3]

            var i:int = 0;

            var exp_id:String = ""; for(i = 0; i < 7; i++) exp_id += String.fromCharCode(0);

            var exp_data:ByteArray = new ByteArray(); for(i = 0; i < 16; i++) exp_data.writeByte(0);

            var argl:Vector.<ProgramArgument> =

                new <ProgramArgument>[new ProgramArgument(new EBCDIC(20),


                                                          "Q007      QGPL"),

                                      new ProgramArgument(new EBCDIC(1),



                                      new ProgramArgument(new Bin4(),



                                      new ProgramArgument(new EBCDIC(1),



                                      new ProgramArgument(new Bin4(),



                                      new ProgramArgument(new EBCDIC(64),



                                      new ProgramArgument(new CompositeType(new Bin4(),

                                                                            new Bin4(),

                                                                            new EBCDIC(7),

                                                                            new EBCDIC(1),

                                                                            new HexData(16)),


                                                          new CompositeData(32,





                                                          ) // Qus_EC_t

                                      ];  // [4]

            try {

                pgm_call.callx(this, enq_callback, argl);  // [5]

            } catch(e:*) {

                trace("RemoteCommand.callx() failed:", e);

            } finally {

                trace("After invoking RemoteCommand.callx().");





        private function enq_callback(rc:int,


                                      msg:String = null) : void {   // [6]

            trace("Call to ENQ returns with return code:", rc);




A detailed explanation of the scenario follows:


1. Before running t007.swf, you need to create USRQ QGPL/Q007 that t007.swf is going to operate on by calling the Create User Queue (QUSCRTUQ) API. For example, you may call QUSCRTUQ interactively at a command line entry like so:


CALL PGM(QUSCRTUQ) PARM('Q007      QGPL'    /* Qualified USRQ name */

                        'UUQQ'              /* Extended attribute */

                        'F'                 /* Queue type = FIFO */

                        X'00000000'         /* Key length = 0 */

                        X'00000040'         /* Maximum message length = 64 */

                        X'00000010'         /* Initial number of messages = 16 */

                        X'00000010'         /* Additional number of messages = 16 */

                        '*CHANGE'           /* Public authority = *CHANGE */

                        'FIFO *USRQ, max message length: 64' /* Text description */



2. If this is your first time running Flash programs against your IBM i server, you need to deploy a cross-domain policy-file server at your IBM i server. Flash Player requires a cross-domain policy file to be loaded from the server it's going to connect to before actually setting up a socket connection to the server. According to the loaded policy, Flash Player determines whether or not to permit a Flash program to connect to the target server at a specific port via socket. See "How to set up a security policy server for Flash clients at an IBM i server" for details.


3. In event listener onBtnClick, a new instance of class RemoteCommand, pgm_call is created. The name of the target IBM i server, user name, password, library, and name of the target IBM i program to call (I5TOOLKIT/ENQ) are passed to the constructor of RemoteCommand.


4. The list of arguments to pass to target program of type Vector.<ProgramArgument> is constructed. Classes EBCDIC, Bin4, and CompositeType are converter classes that implement interface IAS400Data, which is used for converting PC data types to and from IBM i data types.


5. Method RemoteCommand.callx() is invoked on pgm_call to call I5TOOLKIT/ENQ to queue a user message onto USRQ QGPL/Q007. Arguments being passed to RemoteCommand.callx() include these: the object to receive asynchronous notification when the requested program call is completed (in our example, "this," which is the current object), the callback method (enq_callback) to invoke on "this" to send completion notification, and the argument list to pass to the target IBM i program.


6. When the program call is complete, callback method enq_callback is invoked. The argument list passed to the target IBM i program is returned through the second parameter of the callback method, argl, from which you can retrieve the value of any input/output or output-only arguments.


7. CL command DSPQMSG can be used to check the queue entries being put on USRQ QGPL/Q007.


For detailed documentation on AS3 classes involved in the above example, please refer to Class Reference of as-400.

as/400, os/400, iseries, system i, i5/os, ibm i, power systems, 6.1, 7.1, V7, V6R1