23
Tue, Apr
1 New Articles

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

APIs
Typography
  • 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 t007.as.

 

092311Junleihello

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,

                                  i_user.text,

                                  i_pwd.text,

                                  "I5TOOLKIT",

                                  "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),

                                                          ProgramArgument.INPUT,

                                                          "Q007      QGPL"),

                                      new ProgramArgument(new EBCDIC(1),

                                                          ProgramArgument.INPUT,

                                                          String.fromCharCode(2)),

                                      new ProgramArgument(new Bin4(),

                                                          ProgramArgument.INPUT,

                                                          0),

                                      new ProgramArgument(new EBCDIC(1),

                                                          ProgramArgument.INPUT,

                                                          String.fromCharCode(0)),

                                      new ProgramArgument(new Bin4(),

                                                          ProgramArgument.INPUT,

                                                          64),

                                      new ProgramArgument(new EBCDIC(64),

                                                          ProgramArgument.INPUT,

                                                          i_msg.text),

                                      new ProgramArgument(new CompositeType(new Bin4(),

                                                                            new Bin4(),

                                                                            new EBCDIC(7),

                                                                            new EBCDIC(1),

                                                                            new HexData(16)),

                                                          ProgramArgument.INOUT,

                                                          new CompositeData(32,

                                                                            0,

                                                                            exp_id,

                                                                            String.fromCharCode(0),

                                                                            exp_data)

                                                          ) // 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,

                                      argl:Vector.<ProgramArgument>,

                                      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

 

Junlei Li

Junlei Li is a programmer from Tianjin, China, with 10 years of experience in software design and programming. Junlei Li began programming under i5/OS (formerly known as AS/400, iSeries) in late 2005. He is familiar with most programming languages available on i5/OS—from special-purpose languages such as OPM/ILE RPG to CL to general-purpose languages such as C, C++, Java; from strong-typed languages to script languages such as QShell and REXX. One of his favorite programming languages on i5/OS is machine interface (MI) instructions, through which one can discover some of the internal behaviors of i5/OS and some of the highlights of i5/OS in terms of operating system design.

 

Junlei Li's Web site is http://i5toolkit.sourceforge.net/, where his open-source project i5/OS Programmer's Toolkit (https://sourceforge.net/projects/i5toolkit/) is documented.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: