Tech Note 41: Using Adobe Flash with NS Basic

March 10, 2009

© NS BASIC Corporation. All rights reserved.

Contributed by Ian Hatton, Motorola UK

Overview

The Macromedia Flash Player 7 for Pocket PC (http://www.adobe.com/products/flashplayer_pocketpc/downloads/player.html) is an ActiveX control which can be easily incorporated into a NS Basic application as follows:

1. Install Flash Player 7

2. Declare the ActiveX object in your application as follows:

AddObject "ShockwaveFlash.ShockwaveFlash", "Flash1", 10, 10, 100, 100
The above will define a Flash player window which is 100 x 100 pixels in size located at +10,+10 from the top left corner of the screen.

The player supports Flash files in SWF format which can be loaded and played using the command:

Flash1.movie="file://\my documents\myflashfile.swf"
Several other actions are available as shown below:
Flash1.stop  ' pause playback
Flash1.play  ' resume playback
Flash1.zoom(50) ' zoom in 
Flash1.zoom(200) ' zoom out 
Flash1.rewind ' rewind to beginning

Sample Application

Some of these are demonstrated in the sample flash player application below:
AddObject "NSBasic.ComDlg","dialog",0,0,0,0
AddObject "ShockwaveFlash.ShockwaveFlash", "ShockwaveFlash1", 0, 0, 240, 270
Menu = ARRAY("File","Play","Stop","About","Exit")
SETMENU "Titlebar", Menu

Sub play_click
  Shockwaveflash1.play
End Sub

Sub stop_click
  Shockwaveflash1.stop
End Sub

Sub about_click
  Msgbox("NSB Flash Player v1")
End Sub

Sub exit_click
  Bye
End Sub


Sub file_click

  dialog.DialogTitle = "Pick a Flash file to open"
  dialog.InitDir = "\storage card"
  dialog.Filter = "SWF|*.swf"
  dialog.FilterIndex = 1
  dialog.Flags = &H1000 Or &H800 'path and file must exist
  dialog.filename = "" 'initialize

  'Generate error if cancel is pressed
  dialog.CancelError = True
  On Error Resume Next
  dialog.ShowOpen

  'Determine action to take after dialog is dismissed
  If Err.Number = 0 Then
    txtFileName = dialog.filename
  Else
    If Err.Number = 32755 Then MsgBox "Canceled"                        
  End If

  Shockwaveflash1.movie="file://"+txtfilename

End Sub

Documentation

Scripting with Flash Player and ActiveX

The documentation below describes the scripting interface for the Flash Player ActiveX control. This control handles playback of Flash content on Windows machines which support ActiveX.

Experienced scripters should read the article Scripting with Flash for an overview of JavaScript methods which can control the Flash Player. Beginning scripters may benefit more from the example-based TechNotes "An example of communication between JavaScript and Adobe Flash Player" (TechNote 15683) and "An example of communication between Macromedia Flash 5 movies through JavaScript" (TechNote 15692).

PropertiesReadyState (get only) 0=Loading, 1=Uninitialized, 2=Loaded, 3=Interactive, 4=Complete.
TotalFrames (get only) Returns the total number of frames in the movie. This is not available until the movie has loaded. Wait for ReadyState = 4.
FrameNum (get or set) The currently displayed frame of the movie. Setting this will advance or rewind the movie.
Playing (get or set) True if the movie is currently playing, false if it is paused.
Quality (get or set) The current rendering quality (0=Low, 1=High, 2=AutoLow, 3=AutoHigh). This is the same as the QUALITY parameter.
ScaleMode (get or set) Scale mode (0=ShowAll, 1= NoBorder, 2 = ExactFit). This is the same as the SCALE parameter.
AlignMode (get or set) The align mode consists of bit flags. (Left=+1, Right=+2, Top=+4, Bottom=+8). This is the same as the SALIGN parameter.
BackgroundColor (get or set) Override the background color of a movie. An integer of the form red*65536+green*256+blue use -1 for the default movie color.
Loop (get or set) True if the animation loops, false to play once. Same as the MOVIE parameter.
Movie (get or set) The URL source for the Flash Player movie file. Setting this will load a new movie into the control. Same as the MOVIE parameter.
MethodsPlay() Start playing the animation.
Stop() Stop playing the animation.
Back() Go to the previous frame.
Forward() Go to the next frame.
Rewind() Go to the first frame.
SetZoomRect(int left, int top, int right, int bottom) Zoom in on a rectangular area of the movie. Note that the units of the coordinates are in twips (1440 units per inch). To calculate a rectangle in Flash, set the ruler units to Points and multiply the coordinates by 20 to get TWIPS.
Zoom(int percent) Zoom the view by a relative scale factor. Zoom(50) will double the size of the objects in the view. Zoom(200) will reduce the size of objects in the view by one half.
Pan(int x, int y, int mode) Pan a zoomed in movie. The mode can be: 0 = pixels, 1 = % of window.
EventsOnProgress(int percent) Generated as the Flash Player movie is downloading.
OnReadyStateChange(int state) Generated when the ready state of the control changes. The possible states are 0=Loading, 1=Uninitialized, 2=Loaded, 3=Interactive, 4=Complete.
FSCommand(string command, string args) This event is generated when a GetURL action is performed in the movie with a URL and the URL starts with "FSCommand:". The portion of the URL after the : is provided in command and the target is provided in args. This can be used to create a response to a frame or button action in the Shockwave Flash movie.

Flash Media

There are numerous sources for Flash SWF files on the web including the following:

Suggested Uses

This control can be used to add high quality multimedia to an NS Basic application e.g.

More Sample Screenshots