Вы находитесь на странице: 1из 48

The AppCobra API

Contents
The AppCobra API............................................................................................................................1
Contents............................................................................................................................................1
The API...............................................................................................................................................5
What is the API?.............................................................................................................................5
A Simple API Example to Try..........................................................................................................8
Writing Your Own Routines.............................................................................................................9
Text to Appear After the <BODY> tag............................................................................................9
Text to Appear Before the </BODY> tag........................................................................................9
Formatting.......................................................................................................................................9
JavaScript.....................................................................................................................................10
The <SCRIPT> and </SCRIPT> tags...........................................................................................11
Creating your Own Routines.........................................................................................................11
Navigation and Messages..............................................................................................................13
Showing a Message (simple)........................................................................................................13
Showing a Message (advanced)..................................................................................................13
Moving Ahead Single Steps..........................................................................................................13
Moving Back One Steps...............................................................................................................13
Moving Ahead Multiple Steps.......................................................................................................13
Moving Back Multiple Steps..........................................................................................................13
Move Back After Showing Page Corner Animation......................................................................13
Move Forwards After Showing Page Corner Animation...............................................................13
Reload App without Saving User Progress..................................................................................13
Reload App and Saving User Progress........................................................................................14
Launching a URL in a new Window..............................................................................................14
Restarting App..............................................................................................................................14
Replay Step..................................................................................................................................14
Closing App...................................................................................................................................14
Print Current Step.........................................................................................................................14
Set App Status to Complete.........................................................................................................14
Set App Status to Complete But Do Not Submit..........................................................................14
Hide the Keyboard........................................................................................................................14
Generate a random number.........................................................................................................14
Variables..........................................................................................................................................15
Getting User Name.......................................................................................................................15
Getting Step Number....................................................................................................................15
Getting Total Number of Steps.....................................................................................................15
Getting Current Zoom...................................................................................................................15
Determining Browser in Use.........................................................................................................16
App Title........................................................................................................................................16
Screen Width................................................................................................................................16
Screen Height...............................................................................................................................16
Available Screen Width.................................................................................................................17
Available Screen Height...............................................................................................................17
User Results.................................................................................................................................17
Checking if the App is Being Run at Full Screen..........................................................................17

Get Day of Year............................................................................................................................17


Referencing Individual Objects.....................................................................................................18
The Object Alias............................................................................................................................18
Always Use Quotes.......................................................................................................................18
Milliseconds..................................................................................................................................18
Manipulating and Moving Objects................................................................................................19
Hiding and Showing Objects.........................................................................................................19
Positioning an Object....................................................................................................................19
Move Objects................................................................................................................................19
Scale or Resize an Object............................................................................................................20
Rotate an Object...........................................................................................................................20
Set Object Opacity........................................................................................................................20
Put an Object on Top....................................................................................................................20
Put an Object on the Bottom.........................................................................................................20
Set Object Tags............................................................................................................................21
Set Object Tooltip.........................................................................................................................21
Load a New Picture.......................................................................................................................21
Update an Object..........................................................................................................................21
Apply a CSS class to an object.....................................................................................................21
State Button Controls....................................................................................................................22
xgetstate(object)...........................................................................................................................22
xrestorestate(object).....................................................................................................................22
xdownstate(object)........................................................................................................................22
xswapstate(object)........................................................................................................................22
Multiple State Buttons....................................................................................................................22
Accelerometer Routines................................................................................................................23
Set Movement Coordinates..........................................................................................................23
Make an Object Move with Device...............................................................................................23
Stop and Object Moving with Device............................................................................................23
Check Position of Moving Objects................................................................................................23
Dragging Routines..........................................................................................................................24
Allow Dragging..............................................................................................................................24
Prevent Dragging..........................................................................................................................24
Set Drag Coordinates...................................................................................................................24
Reset Drag Coordinates...............................................................................................................24
Respond to Drag Object Start.......................................................................................................24
Respond to Drag Object End........................................................................................................24
Respond to Object Being Dragged...............................................................................................24
Respond to Drag Percentage.......................................................................................................24
Determine Drag Percentage.........................................................................................................24
Getting Object Information............................................................................................................25
getxopacity(object)........................................................................................................................25
getxrotation(object).......................................................................................................................25
getxscale(object)...........................................................................................................................25
getxleft(object)..............................................................................................................................25
getxtop(object)..............................................................................................................................25
getxwidth(object)...........................................................................................................................25
getxheight(object).........................................................................................................................25

getxtag(object)..............................................................................................................................25
getxtag2(object)............................................................................................................................25
getxtag3(object)............................................................................................................................25
xgettext(object).............................................................................................................................25
imagesource(object).....................................................................................................................25
isvis(object)...................................................................................................................................25
xgetref(object)...............................................................................................................................25
overlapx(object1,object2)..............................................................................................................25
Quick Way to Set Event for an Object..........................................................................................26
Getting and Settings Values of Fields..........................................................................................27
Getting the Value of a Freeform Text Entry Field.........................................................................27
Setting the Value of a Freeform Text Entry Field.........................................................................27
Getting the Value of a Date Picker Field......................................................................................27
Setting the Value of a Date Picker Field.......................................................................................27
Getting the Value of a Fill In the Blanks Field...............................................................................27
Setting the Value of a Fill In the Blanks Field...............................................................................27
Getting the Value of a Drop Down List Object..............................................................................27
Referencing Variables Inside Text Objects.................................................................................28
Defining Variables.........................................................................................................................28
Using the Variable.........................................................................................................................28
Unexpected Values.......................................................................................................................30
Using the Clock...............................................................................................................................31
Setting the Time............................................................................................................................31
Getting the Time ..........................................................................................................................31
Using the Calendar.........................................................................................................................32
Checking the Date........................................................................................................................32
Checking the Selected Date.........................................................................................................32
Setting the Date............................................................................................................................32
Canvas Objects...............................................................................................................................33
Transfer an Image to the Canvas.................................................................................................33
Transfer an Image from one Canvas object to another................................................................33
Transfer an Image from a Canvas object to an Image object......................................................33
Custom Draw an Image onto a Canvas........................................................................................33
Trim an Image Object...................................................................................................................33
Trim a Canvas Object...................................................................................................................33
Convert a Canvas to Grayscale....................................................................................................33
Change the Brightness of a Canvas.............................................................................................33
Change the Contrast of a Canvas................................................................................................34
Change the Saturation of a Canvas.............................................................................................34
Changing Red, Green and Blue values of a Canvas....................................................................34
Change the Sharpness of a Canvas.............................................................................................34
Save a Canvas as an Image.........................................................................................................34
Save a Canvas into Local Storage...............................................................................................34
Load an Image from Local Storage into an Image.......................................................................34
Prevent / Allow Drawing................................................................................................................34
Events..............................................................................................................................................35
Events Routines..............................................................................................................................35
When an Object has Finished Moving..........................................................................................35

Refreshing the Cache...................................................................................................................35


Respond to Orientation Change...................................................................................................36
Respond to a Touch Release.......................................................................................................36
Respond to a Touch Down...........................................................................................................36
Respond to a Double Touch.........................................................................................................36
Respond to a Keypress................................................................................................................36
Respond to a Step Change..........................................................................................................36
Respond to Swipe Start................................................................................................................36
Respond to Swipe End.................................................................................................................36
Response to Swipe Progress.......................................................................................................36
Respond to Second Finger Swipe Start.......................................................................................36
Respond to Second Finger Swipe End.........................................................................................36
Respond to Second Finger Swipe Progress.................................................................................37
Respond to Drag Object Start.......................................................................................................37
Respond to Drag Object End........................................................................................................37
Respond to Object Being Dragged...............................................................................................37
Respond to App HTML Being Loaded..........................................................................................37
Respond to App About to Begin...................................................................................................37
Respond to App Being Downloaded.............................................................................................37
Getting a Result from a MessageBox...........................................................................................37
Writing Your Own Routines, Advanced.......................................................................................39
Detailed Routines in Events Dialog Box.......................................................................................39
Detailed Routines in Includes Dialog Box.....................................................................................39
Scrolling Inserted Web Pages and PDF Documents Manually..................................................41
Creating Your Own Scroll Objects................................................................................................41
Other Possible Commands...........................................................................................................42
Watching Accelerometer Events .................................................................................................43
Watching Geolocation Events.......................................................................................................44
Writing Information to the User Machine.....................................................................................45
Setting a Value..............................................................................................................................45
Retrieving a Value.........................................................................................................................45
Creating Dynamic Lists and Handling Results...........................................................................46
Handling Audio...............................................................................................................................48
Forcing Flash Audio to Be Used...................................................................................................48

The API
What is the API?
The API is essentially a series of JavaScript routines you can execute in place of standard
JavaScript events.
Let's look at an example. Say we have a picture on the screen.

We select this image. Now we select the Interact / All Events command.

In the When listbox, we have Object is Pressed, so this will execute when the mouse is
pressed.
In the Perform This Action listbox, we'll select the JavaScript Routine option.

In the Routine to Run, we are going to add a routine that displays a message box.
We enter this text:
xmessage("This is my message.")
It appears like this:

When we run the app, and click on the textbox, here is what we see:

It is that simple. All you need to know is the possible routines you can run, and these are listed
below.
A new way to do the same thing as above but a little more quickly is to select the object,
then select the Interact / Run JavaScript code command. There, you can just add code as
required. No <SCRIPT> or </SCRIPT> tags are required.

A Simple API Example to Try


Let us say you have a graphic on the screen, and you want it to move to a new position on the
screen when it is touched, or clicked. Follow these steps.

Start a new app, and add an object to the screen. Does not really matter what it is an
image, a created graphic, a button, even a text object.

Use the Objects / Alias command to give it the alias myimage.

Select the object, and select the Interact / Run JavaScript Code command.

In the text area, enter the AppCobra API line that reads like this:
o positionx("myimage"10,10)

Click on OK to save the event.

Use the Preview button in the main toolbar to test this out.

When the App appears previewed in a browser, touch, or click on it. It will immediately move to
the position on screen 10 pixels from the top, and 10 pixels from the left, of the screen.

Writing Your Own Routines


Using the Edit / Includes command, you can write your own JavaScript routines that are
added to the app. These can then be executed when any event is interacted with.

Text to Appear After the <BODY> tag


In the Text to Appear After the <BODY> tag text box, you enter HTML and/or JavaScript code
that will execute as the page is loading. This code will, as it says, be placed immediately after
the <BODY> code in the HTML.

Text to Appear Before the </BODY> tag


In the Text to Appear Before the </BODY> tag text box, you enter HTML and/or JavaScript
code that will just before the page finishes loading. This code will, as it says, be placed
immediately before the </BODY> code in the HTML.
This is where almost all routines you create should be placed.

Formatting
This text you enter here should be formatted in one of two ways, depending on whether you are
adding HTML, or JavaScript code. HTML.
If you are adding HTML code, then it should be plain and simple JavaScript code. For example,
if we add some code into the Edit/Includes dialog box (like this):

<DIV style='position:absolute;left:10px;top:10px;z-index:5000;'><IMG
SRC='http://www.appcobra.com/assets/applogonew.gif'></DIV>
This is code that loads an image, places it at the 10 pixel by pixel mark on the screen, and
places it on top.

JavaScript
With JavaScript code, you have to be a little more careful. This is because it must be formatted
correctly to ensure that no errors are generated.
Here is an example. Say we add this code to the app using the Edit / Includes dialog box:
<SCRIPT>
alert ("hello")
</SCRIPT>
When we run this app, this is what will appear:

This will appear before any content actually appears on the page.
If this were added to the Text to Appear Before the </BODY> tag area, it would appear after
the content had appeared.

The <SCRIPT> and </SCRIPT> tags


Whenever JavaScript code is used, it must always be enclosed in <SCRIPT> and </SCRIPT>
codes, as per the example above. Failure to do this may cause the app to fail.

Creating your Own Routines


Let's say, using the above dialog box, you add this code:

Note that we used standard JavaScript to create a routine called myroutine().


This will be added to our app:

If we use the example we had at the start of this document, with the image, here is what we
would add in the Interact / Run JavaScript Code dialog box for that image. When we run this
app, here is what we see when we click on the object:

Navigation and Messages


Showing a Message (simple)
Syntax: xmessage(themessage)
Where themessage is the message to display.

Showing a Message (advanced)


Syntax: showamessage(themessage, nextevent, showcancel)
Where themessage is the message to display, nextevent is what happens after the messages,
and showcancel is true or false depending on whether a cancel button should be shown as
well. Nextevent can be "next", "skip2", "skip3", "skip4", "skip5", skip6", "skip7", "skip8", "skip9",
"skip10", "ahead2", "ahead3", "ahead4", "ahead5", "ahead6", "ahead7", "ahead8", "ahead9",
"ahead10", "back2", "back3", "back4", "back5", "back6", "back7", "back8", "back9", "back10",
"back", "close", "", or "restart".
Next goes to next step, back goes to previous step. Aheadx goes ahead x steps, backx goes
back x steps. Skipx goes ahead x steps without incrementing any scoring. If this parameter is
just "", the msgbox is simply hidden.

Moving Ahead Single Steps


Syntax: gotonext()
Moves ahead 1 step. This assumes that this can be done in your app i.e. you are not looking
at the last step, for example.

Moving Back One Steps


Syntax: gotoprevious()
Moves back 1 step. This assumes that this can be done in your app i.e. you are not looking at
the last step, for example.

Moving Ahead Multiple Steps


Syntax: movesteps(x)
Where x is the steps to move forward. This assumes that this can be done in your app i.e. you
are not looking at the last step, for example.

Moving Back Multiple Steps


Syntax: moveback(x)
Where x is the steps to move back. This assumes that this can be done in your app i.e. you
are not looking at the first step, for example.

Move Back After Showing Page Corner Animation


Syntax: goleft()
Moves the app one step back after showing animation.

Move Forwards After Showing Page Corner Animation


Syntax: goright()
Moves the app one step forward after showing animation.

Reload App without Saving User Progress


Syntax: reloadapp()
Reloads the app without saving changes.

Reload App and Saving User Progress


Syntax: saveandreloadapp()
Reloads the app and saves user progress.

Launching a URL in a new Window


Syntax: launchurl("x")
Where x is equal to the fully qualified URL to launch.

Restarting App
Syntax: restart()
Will restart the app.

Replay Step
Syntax: watchstepagain()
Will play the current step again, with all appearance and disappearance delays and animations.

Closing App
Syntax: closeit()
Will close the app immediately (if running in a web browser). Does nothing if actually running as
an app (apps cannot close themselves).

Print Current Step


Syntax: print()
Will cause the Print dialog box to appear, and allow user to print the current step.

Set App Status to Complete


Syntax: setcomplete()
Sets the app status to complete. Only really relevant when connected to a Learning
Management System.

Set App Status to Complete But Do Not Submit


Syntax: setcompletenosubmit()
Sets the app status to complete, but does not yet submit results. Only really relevant when
connected to a Learning Management System.

Hide the Keyboard


Syntax: hidekeyboard()
Hides mobile on screen keyboard. This is normally hidden automatically, but may sometimes
need to be manually hidden.

Generate a random number.


Syntax: randomx(start, end)
Returns random value between start and end

Variables
In many cases, there are a range of variables that can be used. These might be used to alter
what displays in a message box, to whether a command is executed or not. For example let's
assume you want to display to someone their screen resolution. You could construct a
JavaScript event that looks like this:
xmessage("Your screen resolution is " + screen.width + " x " + screen.height + ".")
When this event is executed, it will display something like this:

This is explained in a little more detail below. Using variables requires exact syntax, or error
messages will occur.
Below, we list some of the variables available within AppCobra, plus some common JavaScript
variables.
Actually, any JavaScript variable can be used.

Getting User Name


Syntax: getusername()
Returns the user name. Only works if connected to a Learning Management System.

Getting Step Number


Syntax: getstepnumber()
Returns the current step the user is looking at.

Getting Total Number of Steps


Syntax: getduration()
Returns the total number of steps in the current app.

Getting Current Zoom


Syntax: getzoom()
Returns the current zoom level in the app, where 1 is 100%.

Determining Browser in Use


You can actually use any navigator variables (such as navigator.appName, for example), but
here are a couple of simplified ones:
Syntax: getie()
Returns true if user using any version of Internet Explorer.
Syntax: getie8()
Returns true if user using version 8 or greater of Internet Explorer.
Syntax: getie10()
Returns true if user using version 10 or greater of Internet Explorer.
Syntax: getff()
Returns true if user using FireFox.
Syntax: getsafari()
Returns true if user using Safari.
Syntax: getiphone()
Returns true if user using an IPhone.
Syntax: istouchdevice
A variable that returns true if running on a touch enabled device - otherwise false.
Syntax: isandroid
A variable that returns true if running on android device - otherwise false.
Syntax: isios
A variable that returns true if running on an iOS device - otherwise false.
Syntax: isios6
A variable that returns true if running on an iOS device, using iOS6 or higher.
Syntax: isios7
A variable that returns true if running on an iOS device, using iOS7 or higher.
Syntax: ishoney
A variable that returns 1 if running on Android Honeycomb or higher.
Syntax: istouch
A variable that returns true if running on a Windows 8 or higher touch enabled device otherwise false.
Syntax: iswk
A variable that returns true if running on a WebKit enabled browser.

App Title
Syntax: document.title
Returns the name of the app.

Screen Width
Syntax: screen.width
Returns the width of the screen in pixels.

Screen Height
Syntax: screen.height

Returns the height of the screen in pixels.

Available Screen Width


Syntax: screen.availWidth
Returns the available width of the screen in pixels.

Available Screen Height


Syntax: screen.availHeight
Returns the available height of the screen in pixels.

User Results
Syntax: getresults()
Returns all user results in the app.

Checking if the App is Being Run at Full Screen


Syntax: navigator.standalone
If navigator.standalone is equal to true, then the app is being run as a full screen app,
otherwise it is a web app. This code should be placed inside code to ensure it is only run on an
iPhone or iPad.

Get Day of Year


Syntax: dayofyear()
Where dayofyear will equal the current day of the year, in a number. This can be used to
determine what day of the year it is, if you are creating a quote of the day, pic of the day app,
etc.

Referencing Individual Objects


Using the AppCobra API, you can access and manipulate individual objects quite easily. Details
are below. However, before you use these routines, you should understand a couple of things.

The Object Alias


All objects are referenced using their Alias (set using the Objects / Alias command). However,
note that AppCobra will, when the app is exported or previewed, modify any alias's you may
have set in a couple of ways. Characters such as . , : ; ' and " are removed. All spaces are
removed. The alias is set to lower case.
So, if you have an object in AppCobra that has the alias Rectangle 001, you need to

reference this, in any JavaScript, or AppCobra API routines, as


rectangle001.
My_Image needs to be referenced as myimage.
object001 is referenced as object001

The!Object is referenced as theobject


Always Use Quotes
An example. Below, you will see there is a routine that allows you to position an object on the
screen. It is document as:
positionx(object,x,y)
To use this routine in AppCobra, it would be used as such:
positionx("aliasname",100,100)
where this would place the object called aliasname to the position 100 pixels

from the left, and 100 pixels from the top of the screen.
Always include the object name in quotes! The example below will result in a

JavaScript error, and the app may not run correctly.


positionx(aliasname,100,100)

WRONG!

positionx("aliasname",100,100)

RIGHT!

Milliseconds
Many routines below involve some sort of timing. For example:
hidexdelay(object, x)
Will hide an object after a delay of x milliseconds. 1000 milliseconds is 1 second. So
hidexdelay("aliasname",1000)
Will hide an object after 1000 milliseconds, or one second.
hidexdelay("aliasname",5000)
Will hide an object after 5000 milliseconds, or five seconds.
hidexdelay("aliasname",1)
Will hide an object after 1 millisecond or 1/1000 of a second or essentially, immediately!

Manipulating and Moving Objects


Hiding and Showing Objects
hidexobject(object)
Hides object
showxobject(object)
Shows object
hidexdelay(object, x)
Hides an object after x milliseconds
showxdelay(object, x)
Shows an object after x milliseconds
hidexpermanent(object)
Hides an object permanently
setonoffx(object,xon,xoff)
Sets an object to appear on xon through to xoff steps
restoreonoffx(object)
Restores original on and off steps to object
hidexall(object1_object2)
Hides a range of objects at once. Separate each object by an underscore.
showxall(object1_object2)
Shows a range of objects at once. Separate each object by an underscore
hidegroupp(group)
Hides all objects in the group called group.
showgroupp(group)
Shows all objects in the group called group.

Positioning an Object
positionx(object,x,y)
Positions object to x,y pixels
centerx(object,x,y)
Centers object around x,y pixels
xalign(object,align)
Aligns object to align, relative to canvas. Options are 'topleft', 'topcenter', 'topright', 'bottomleft',
'bottomcenter', 'bottomright', 'center', 'centerleft', 'centerright'
xrestorepos(object)
Restores object to original position
setoffset(object,x,y)
Moves object to new position which is x and y pixels from current position. Can be negative
values as well.
xrandompos(object,left,top,right,bottom)
Randomly positions an object within the given coordinates.

Move Objects
xmoveto(object,fromx,fromy,tox,toy,delay,totaltime)
Moves an object from fromx,fromy to tox,toy (pixels), at delay intervals (milliseconds).
Totaltime is total effect time in milliseconds
offbottomx(object,timedelay,stepdelay)
Moves an object off bottom of screen, at timedelay intervals, at stepdelay increments, and
hides it

offtopx(object,timedelay,stepdelay)
Moves an object off top of screen, at timedelay intervals, at stepdelay increments, and hides it
offleftx(object,timedelay,stepdelay)
Moves an object off left of screen, at stepdelay intervals, at stepdelay increments, and hides it
offrightx(object,timedelay,stepdelay)
Moves an object off right of screen, at stepdelay intervals, at stepdelay increments, and hides
it
wobblex(delay,object,offset,totaltime,timeinterval)
Wobbles an object on the screen. Delay is milliseconds before wobble begins. Offset is pixel
number to wobble over. Totaltime is milliseconds of total event duration. Timeinterval is in
milliseconds and represents time between each wobble.

Scale or Resize an Object


xscale(object,percent)
Scales object to percent (where 1 is current size)
xscalecenter(object,percent)
Scales an object to percent
xscaleto(object,from,to,delay,totaltime,alignx)
Scales an object from from to to, at delay intervals (milliseconds). Totaltime is total effect time
in milliseconds
xrestoresize(object)
Restores original size to object

Rotate an Object
xrotate(object,degrees)
Rotates object to x degrees plus current object rotation
xrotateto(object,from,to,delay,totaltime)
Rotates an object from from(%) to to(%), at delay intervals (milliseconds). Totaltime is total
effect time in milliseconds
xrotatefixed(object,degrees)
Rotates object to x degrees

Set Object Opacity


xopacity(object, opacity)
Changes opacity of object to opacity (from 0 to 1)
xopacityto(object,from,to,delay,totaltime)
Changes opacity of an object from from (0 to 1) to to (0 to 1), at delay intervals. Totaltime is
total effect time in milliseconds
xrestoreopacity(object)
Restores original opacity to object
xfadeout(object, mseconds)
Fades out an object in mseconds milliseconds, then hides it

Put an Object on Top


ontopx(object)
Puts an object on top of other objects

Put an Object on the Bottom


onbottomx(object)
Puts an object on bottom of other objects

Set Object Tags


setxtag(object,tag, delay)
Sets value of tag1 for object with tag after delay milliseconds
setxtag2(object,tag, delay)
Sets value of tag2 for object with tag after delay milliseconds
setxtag3(object,tag, delay)
Sets value of tag3 for object with tag after delay milliseconds

Set Object Tooltip


setxtitle(object,tooltip)
Sets tooltip for object

Load a New Picture


loadnewpicture(object,image,width,height)
Loads a new picture into an object. Image is URL or image reference, at width, height pixels

Update an Object
updatexobject(object)
Updates an object where a variable has changed value

Apply a CSS class to an object


applyclassx(object, theclass, complete)
Applies a CSS class to an object. If complete is true, this is the only style - if not, style is
added.

State Button Controls


State buttons work in the following way.
First, set up a button, or buttons, with an imagedown object (Effects/Touchdown Image). The
image you select as a touchdown image will be the 'down' state for this object.
Then, in the toolbar that appears just above the object on the canvas when you select it, select
the Object Tag button. Give it the tag state.
You can give this button an event as normal if you wish.
Because you added the tag state, when this button is selected, the down state replaces the
normal state. When selected again, the normal state, or up state, returns.
Using the API, you can manually get or set the state of a button.

xgetstate(object)
returns either "up" or "down", depending on the current state of object.

xrestorestate(object)
returns object to its normal, or up state

xdownstate(object)
Sets object to its down state

xswapstate(object)
Swaps the current state of object.

Multiple State Buttons


If you create multiple state buttons using the above procedure, and place these buttons in the
same group (see the Groups Toolbar), then only one button in the group can be in the down,
or selected state. The app will automatically set all other buttons to the up state whenever any
one button in the group is set to the down state, either manually, or by user selection.

Accelerometer Routines
Set Movement Coordinates
xsetdragcoords(object,left,top,right,bottom)
Sets the area in which the object being dragged can only be dragged within.

Make an Object Move with Device


xmakemoveable(object,speed)
makes the object respond to the accelerometer. The speed can be from 1 to 9, where 1 s the
slowest.

Stop and Object Moving with Device


xmakenotmoveable(object)
Stops the object responding to the accelerometer.

Check Position of Moving Objects


objectsmoved()
Routine that is called each time the objects are moved on screen

Dragging Routines
Allow Dragging
allowdragx(object)
Allows an object to be dragged around the screen

Prevent Dragging
preventdragx(object)
Prevents an object from being dragged around the screen

Set Drag Coordinates


xsetdragcoords(object,left,top,right,bottom)
Sets the area in which the object being dragged can only be dragged within.

Reset Drag Coordinates


resetxsetdragcoords(object)
Resets the drag coordinates of an object so it can be dragged anywhere.

Respond to Drag Object Start


dragstart(object)
Activated when an object is started being dragged

Respond to Drag Object End


dragended(object)
activated when an object is finished being dragged

Respond to Object Being Dragged


dragging(object)
activated when an object is being dragged.

Respond to Drag Percentage


dragpercent(object,percentage)
activated when an object is being dragged. Percentage reflects, from 0 to 1, how far the object
has been dragged if the xsetdragcoords routine has been used to set drag coordinates.

Determine Drag Percentage


dragpercent(object,percentage)
Used to query the percentage of an object being dragged along a slider. Percentage reflects,
from 0 to 1, how far the object has been dragged if the xsetdragcoords routine has been used
to set drag coordinates.

Getting Object Information


getxopacity(object)
Returns opacity of object (0 to 1)

getxrotation(object)
Returns rotation of object (degrees)

getxscale(object)
Returns scale of object (where 1 is original size)

getxleft(object)
Returns left position of object in pixels

getxtop(object)
Returns top position of object in pixels

getxwidth(object)
Returns width of object in pixels

getxheight(object)
Returns height of object in pixels

getxtag(object)
Returns value of tag1 for object

getxtag2(object)
Returns value of tag2 for object

getxtag3(object)
Returns value of tag3 for object

xgettext(object)
Returns text of object

imagesource(object)
Returns image source for object

isvis(object)
Returns true or false based on whether object is visible or not

xgetref(object)
Returns internal reference of object

overlapx(object1,object2)
Returns true or false on whether the object called object1 overlaps the object called object2
(centrally), and both are visible.

Quick Way to Set Event for an Object


Let us say you have a graphic on the screen, and you want it to wobble on the screen when
clicked. Let us assume that the object has the alias 'myimage'.
Normally, you would select the object, and select the Object/Event command. You would
select JavaScript Routine in the Perform This Action listbox. Finally, in the Routine to Run
text area, you would enter the AppCobra API line that reads like this:
wobblex(0,"myimage"10,5000,100)
This will 'wobble' the object called myimage randomly over a 10 pixel radius. The total effect
will last for 5000 milliseconds (5 seconds), and each movement would occur at intervals of 100
milliseconds (1/10 of a second).
However, because we are activating this event by clicking on the object itself, we could modify
this command to read:
wobblex(0,(x)10,5000,100)
where (x) is replaced by the object name automatically by AppCobra.

Getting and Settings Values of Fields


Getting the Value of a Freeform Text Entry Field
getvaluex(object)
returns the value of an freeform text entry field. This value will change as the user edits the text.

Setting the Value of a Freeform Text Entry Field


setvaluex(object, "the new value")
sets the value of the text in a freeform text entry field. In the example above, the freeform text
entry object will have the text "the new value" in it.

Getting the Value of a Date Picker Field


getvaluex(object)
returns the value of a data entry field. This value will change as the user makes any selections.
The result from a date picker field is always in the format YYYY-MM-DD.

Setting the Value of a Date Picker Field


setvaluex(object, "2012-12-31")
sets the value of the text in a date picker field. In the example above, the date picker object will
reflect the date 31st December, 2012. The value must always be in the format YYYY-MM-DD,
otherwise the date picker will not be updated.

Getting the Value of a Fill In the Blanks Field


getvaluemx(object,1)
returns the value of an entry in the fill in the blanks object. This value will change as the user
edits the text. Change 1 to the number item you want to get the value of because a fill in the
blanks object can have multiple entries.

Setting the Value of a Fill In the Blanks Field


setvaluemx(object,1,"value")
sets the value of an entry in the fill in the blanks object. Change 1 to the number item you want
to set the value of because a fill in the blanks object can have multiple entries.

Getting the Value of a Drop Down List Object


getvalueddx(object,dropdownlistnumber)
returns the text of the currently selected item in a drop down list. dropdownlistnumber is the
number of the drop down list to grab (as any object can have a number of drop down lists
associated with it).

Referencing Variables Inside Text Objects


Defining Variables
Let's assume that you have created (defined) a variable, using the Edit/Includes command:

In the example above, we have created a variable called myvalue.

Using the Variable


We can use this inside any text object, using this syntax:

When we run the app, it will look like this:

If you referenced a variable that you have not created, or misspell a variable name (variables in
JavaScript are case sensitive), the screen would look like this.

When a variable in the format %%%variable%%% is used, it is evaluated each time a step is
changed. So, you can change the value of the variable just remember that it will not update in
the text object until the step changes. Shortly, you'll see there is a routine you can run that will
update any object that contains a variable:
updatexobject(object)

Unexpected Values
If the text box displays an unexpected value say 18 instead of myvalue value, for example, it
may mean that you have used one of the reserved variables used by the AppCobra app itself.
Such variables include score, possiblescore, pause, pauses, noerrors, closemethod, etc.

Using the Clock


The following API calls assume that you have added a Clock object to your app, and have given
it the alias clock. To use these calls, you must have set the clock object to be a specific time,
rather than one of the dynamic options.

Setting the Time


Syntax: xsethour(clock,xhour)
Sets the hour on the object with the alias clock.
Syntax: xsetminute(clock,xminute)
Sets the minute on the object with the alias clock.
Syntax: xuphour(clock)
Increments the hour on the object with the alias clock.
Syntax: xdownhour(clock)
Decrements the hour on the object with the alias clock.
Syntax: xupminute(clock)
Increments the minute on the object with the alias clock.
Syntax: xdownminute(clock)
Decrements the minute on the object with the alias clock.

Getting the Time


Syntax: xgethour(clock)
Returns the hour on the object with the alias clock.
Syntax: xgetminute(clock)
Returns the minute on the object with the alias clock.

Using the Calendar


The following API calls assume that you have added a Calendar object to your app, and have
given it the alias calendar.

Checking the Date


Syntax: calendarselected()
This routine is run when a user selects a date from the calendar. To use this, you must add the
following routine to your App:
function calendarselected(){
//your code
}
Syntax: xxcalmonth()
Returns the month selected in the calendar object, from 1 to 12.
Syntax: xxcalmonthstring()
Returns the month selected in the calendar object as a string (January, for example).
Syntax: xxcalday()
Returns the date selected in the calendar object.
Syntax: xxcalyear()
Returns the year selected in the calendar object.
Syntax: xxtoday()
Sets the calendar object to todays date.
Syntax: xxclearcalendar()
Removes any user selection from the calendar.

Checking the Selected Date


Syntax: xxcalmonthselected()
Returns the month selected by the user in the calendar object (from 1 to 12).
Syntax: xxcalmonthselectedstring()
Returns the month selected by the user in the calendar object as a string (January, for
example).
Syntax: xxcaldayselected()
Returns the date selected by the user in the calendar object.
Syntax: xxcalyearselected()
Returns the year selected in the calendar object.

Setting the Date


Syntax: xxsetdate(dd,mm,yy)
Sets the date in the calendar object, where dd = the date, mm = the month, and yy = the year.
Syntax: xsetdateselected(dd,mm,yy)
Sets the date, and selects this date, in the calendar object, where dd = the date, mm = the
month, and yy = the year.

Canvas Objects
The following canvas API calls assume that you have added a canvas object to your app.

Transfer an Image to the Canvas


Syntax: imagetocanvas(theimage,thecanvas)
This routine transfers the image from the AppCobra object with the alias theimage into the
AppCobra canvas with the alias thecanvas.

Transfer an Image from one Canvas object to another


Syntax: canvastocanvas(fromcanvas, tocanvas, left, top, width, height, leftoffset,
topoffset)
This routine transfers the image from the AppCobra canvas object with the alias fromcanvas
into the AppCobra canvas with the alias tocanvas. The coordinates left, top, width, height
determine the part of the image transferred. These are all optional. Leftoffset is the left offset in
the target canvas where the image is placed. Topoffset is the top offset in the target canvas
where the image is placed.

Transfer an Image from a Canvas object to an Image object


Syntax: canvastoimage(thecanvas,theimage)
This routine transfers the image from the AppCobra canvas object with the alias thecanvas into
the AppCobra object with the alias theimage.

Custom Draw an Image onto a Canvas


Syntax: addimagetocanvas(theimage,thecanvas,left,top,width,height,xalpha,xrotate)
This routine transfers the image from the object with the alias theimage into an AppCobra
canvas object with the alias thecanvas. It appears at left, top coordinates, at a width of width
and a height of height pixels. alpha (from 0 to 1) determines how transparent the object is.
rotation determines the angle of the object drawn.

Trim an Image Object


Syntax: trimimage(theimage, left, top, width, height)
Trims, or crops the AppCobra object with the alias theimage to the coordinates determined by
left, top, width and height.

Trim a Canvas Object


Syntax: trimcanvas(thecanvas, left, top, width, height)
Trims, or crops the AppCobra canvas object with the alias thecanvas to the coordinates
determined by left, top, width and height.

Convert a Canvas to Grayscale


Syntax: canvasgreyscale(thecanvas, left, top, width, height)
Converts the AppCobra canvas object with the alias thecanvas to greyscale. Left, top, width
and height are optional, but if specified, represent the area of the canvas image to modify.

Change the Brightness of a Canvas


Syntax: canvasbrighten(thecanvas, amount, left, top, width, height)
Changes the brightness of the AppCobra canvas object with the alias thecanvas. Amount can
be negative or positive. Left, top, width and height are optional, but if specified, represent the
area of the canvas image to modify.

Change the Contrast of a Canvas


Syntax: canvascontrast(amount, thecanvas, left, top, width, height)
Changes the contrast of the AppCobra canvas object with the alias thecanvas. Amount can be
negative or positive. Left, top, width and height are optional, but if specified, represent the
area of the canvas image to modify.

Change the Saturation of a Canvas


Syntax: canvassaturate(amount, thecanvas, left, top, width, height)
Changes the saturation of the AppCobra canvas object with the alias thecanvas. Amount can
be negative or positive. Left, top, width and height are optional, but if specified, represent the
area of the canvas image to modify.

Changing Red, Green and Blue values of a Canvas


Syntax: canvasrgb(red, green, blue, thecanvas, left, top, width, height)
Changes the red, green, and/or blue values of the AppCobra canvas object with the alias
thecanvas. Amount can be negative or positive. Left, top, width and height are optional, but if
specified, represent the area of the canvas image to modify.

Change the Sharpness of a Canvas


Syntax: canvassharpen(amount, thecanvas, left, top, width, height)
Changes the sharpness of the AppCobra canvas object with the alias thecanvas. Amount can
be from 1 to 5. Left, top, width and height are optional, but if specified, represent the area of
the canvas image to modify.

Save a Canvas as an Image


Syntax: savecanvas(thecanvas, thetext)
Opens up a messagebox displaying thetext. When selected, the image in the AppCobra
canvas object with the alias thecanvas will be loaded into its own browser window, and can be
saved by the user.

Save a Canvas into Local Storage


Syntax: saveimagelocal(thecanvas, imagename)
Saves the image in the canvas with the alias thecanvas to a local file called imagename. Note
that this is saved in the apps sandbox, and can only be accessed by your app.

Load an Image from Local Storage into an Image


Syntax: loadimagelocal(imagename, theimage)
Loads the image imagename in the image object with the alias theimage. You cannot load just
any file in this manner - only an image you saved previously using the saveimagelocal
command.

Prevent / Allow Drawing


By default, whenever you create a canvas object, drawing is enabled and allowed. To prevent
any user drawing from occurring, set the following variable value:
preventdraw=true this prevents drawing from taking place.
preventdraw=false default allows drawing to take place.

Events
There are several events that will be triggered under certain circumstances.
As these are events, they are generated by the app itself. So, there is a little extra something
you need to add.
For example, let us say that you want something to happen when the user gets to step 3 in your
app. Normally, you could just add something to step 3 in your app, but for this example let us
say we want to display a message when the user reaches step 3.
To do this, we need to add the routine that corresponds to the event we want to respond to,
using the Edit / Includes command. In this case, we would have to add (in the Code to Appear
before the </BODY> tag section):
<SCRIPT>
function stepchangex(t){
}
</SCRIPT>
Adding this routine allows us to add whatever JavaScript, or AppCobra API code we like to
occur at step 3. For example, this code will display a message when the user gets to step 3:
<SCRIPT>
function stepchangex(t){
if (t==3){
xmessage("You are on step 3!")
}
}
</SCRIPT>
In this routine, the variable t represents the current step number.
Here is something slightly smarter. Let us assume we want to display a message when they get
to step 3, but only the very first time they get to step 3. This code might look like this:
<SCRIPT>
var messageshown=false
function stepchangex(t){
if (t==3&&messageshown==false){
xmessage("You are on step 3!")
messageshown=true
}
}
</SCRIPT>
Here, we've created a variable called messageshown. When the user gets to step 3, we check
to see whether this variable is set to true, or false. If false, we show the message, and set the
value of the variable to true. From now on, this message will not display, even if the user comes
back to Step 3 at a later stage.

Events Routines
When an Object has Finished Moving
xmovedone(object)
is executed when a move is completed

Refreshing the Cache


updateCache()
This is only used if you have selected to create a HTML5 manifest connected to your app.
Updates the cache from the original server.

Respond to Orientation Change


function ohc(){}
When the iPhone/iPad/Tablet changes orientation, this event is triggered (you'd have to add this
event in the code somewhere yourself.)
Example:
function ohc(){
if(window.orientation==0){
//device is vertical
}
if(window.orientation!=0){
//device is horizontal
}
}

Respond to a Touch Release


function mouseupx(t){}
This occurs when a mouse is released on an object with an event. t represents the object name.

Respond to a Touch Down


function mousedownx(t){}
This occurs when a mouse is clicked on an object with an event. t represents the object name.

Respond to a Double Touch


function mousedoublex(t){}
This occurs when a mouse is double-clicked on an object with an event. t represents the object
name.

Respond to a Keypress
function keypressx(t){}
This occurs when a keyboard button is pressed. t is the keyboard button.

Respond to a Step Change


function stepchangex(t){}
This occurs when a step changes. t represents the step number.

Respond to Swipe Start


function firsttouchstart(xx,yy){}
where xx and yy are the swipe coordinates of the swipe start.

Respond to Swipe End


function firsttouchend (xx,yy){}
where xx and yy are the swipe coordinates of the swipe end.

Response to Swipe Progress


function firsttouch (xx,yy){}
where xx and yy are the swipe coordinates of the swipe in progress.

Respond to Second Finger Swipe Start


function secondtouchstart(xx,yy){}
where xx and yy are the swipe coordinates of the second finger swipe start.

Respond to Second Finger Swipe End


function secondtouchend(xx,yy){}
where xx and yy are the swipe coordinates of the second finger swipe.

Respond to Second Finger Swipe Progress


function secondtouch(xx,yy){}
where xx and yy are the swipe coordinates of the second finger swipe.

Respond to Drag Object Start


dragstart(object)
Activated when an object is started being dragged

Respond to Drag Object End


dragended(object)
activated when an object is finished being dragged

Respond to Object Being Dragged


dragging(object)
activated when an object is being dragged.

Respond to App HTML Being Loaded


apphasloaded()
This is activated when the HTML app becomes interactive. All images may not have loaded, but
all HTML has.

Respond to App About to Begin


its()
The app has completely finished being loaded, and is about to display step 1.

Respond to App Being Downloaded


apphasdownloaded()
If the app is set to download to a local machine, this event is activated when the download is
complete.

Getting a Result from a MessageBox


Normally, using code like:
showamessage("This is my message.","" , false)
will show a message box. You can tell when a MsgBox has been clicked when you add a
routine to your code called customx:
function customx(){
//this is activated when a msgbox is clicked
}
Let's look at an example. Let's say you want someone to confirm whether an object/file/entry
should be deleted. You could add this code:
checkingfordeleteok=true
showamessage("Are you sure you want to delete this file?","" ,true)
By adding the true to as the third parameter in this command, we get an OK and a Cancel
button. We added a variable called checkingfordeleteok, so that when the MsgBox is clicked,
we know under what circumstances it appeared in the first place.
So, once this activates, we simply add some code to the customx routine, something like this:
function customx(){
if (checkingfordeleteok==true){

//this means we are checking


//for this particular msgbox

if (okpressed){
//this means the user has clicked on OK.
}

}
checkingfordeleteok=false

//we always set this to false here to ensure


//that we don't check it accidentally again some time

}
If you have use messageboxes a lot, you will find the customx routine will end up looking
something like this:
//first, we declare the variables we are going to use to check messagebox results
var checkingfordeleteok=false
var checkingtoaddfile=false
varcheckingtoclosedown=false
function customx(){
if (checkingfordeleteok==true){
if (okpressed){
//the user has clicked on OK in response to the checking to delete a file
question.
}
}
if (checkingtoaddfile==true){
if (okpressed){
//the user has clicked on OK in response to the checking to adding a file
question.
}
}
if (checkingtoclosedown==true){
if (okpressed){
//the user has clicked on OK in response to the checking to closing a file
question.
}
}
checkingfordeleteok=false
checkingtoaddfile =false
checkingtoclosedown =false
}

Writing Your Own Routines, Advanced.


Detailed Routines in Events Dialog Box
Before we look at some more detailed routines one more thing. Above, when we've used the
JavaScript Routine option for an event, we've always added something simple, like
myroutine() or alert("Hello").
You can put more details routines in here as long as they all appear on one line. For example,
you could put this:
for(i=0; i<f.length; i++){if(f[i].objectname=="help")
{f[i].object.style.visibility="hidden"}}

Detailed Routines in Includes Dialog Box


Here we are going to combine a few features we've seen here to create a JavaScript routine
like this:

In this case, we add, as we've done above, the JavaScript event myroutine() to an object:

When the user clicks on this object, the routine you've written called myroutine() executes.
Now, in this routine, we added some logic (highlighted in red):
<SCRIPT>
function myroutine(){
if (getstepnumber()==1){
alert ("hello")
}
}
</SCRIPT>
Here, using standard JavaScript notation, we are in effect saying if the user is looking at Step
1, then display an alert. Otherwise don't do anything.
How inventive you get depends on you. Here is another, slightly more complex example.
<SCRIPT>
function myroutine(){
if (getstepnumber()==1){
alert ("You are looking at Step 1.")
}else{
If (getstepnumber()=getduration()){
alert ("You are looking at Step " + getstepnumber() + ", last step in the app.")
}
}
}
</SCRIPT>
In this case, the user will see a message that reads You are looking at Step 1. if they are on
step 1, and a message that reads You are looking at Step 10, the last step in this app.
(assuming Step 10 was the last step in that app).

Scrolling Inserted Web Pages and PDF Documents Manually


Creating Your Own Scroll Objects
You can create your own scrolling controls for imported web pages or PDFs. Take the following
screen as an example:

:
In this example, we've added an arrow that points up, and an arrow that points down. There are
some special events that allow you to let these arrows control scrolling in this web object.
For this example, we assume that the actual web page object is called appcobra. To confirm
this, select the main web object, and use the Objects/Alias command to ensure it is called
appcobra

Now we can add the events to the arrows we added.


This is slightly advanced it actually uses the AppCobra API, but quite simple to follow. First,
we select the arrow that points upwards. We then select the Objects / Event command. We
give this object this event.

We've done two things first, we select the option JavaScript Routine from the Perform This
Action listbox. Then, in the Routine to Run: area, we added the text:
xscrollup("appcobra")
where appcobra is the web object we want to control, and xscrollup can be either xscrollup,
xscrolldown, xscrollright, or xscrollleft.
Once you've applied any combination of these events, AppCobra will do the rest. That object
will then let you scroll the web object up, down, left or right.

Other Possible Commands


Here is a complete list of possible JavaScript functions you can use, as above, to control the
content in your inserted web page or PDF.
These examples assume an object called appcobra.

xscrollup("appcobra") scrolls the content up, if possible


xscrolldown("appcobra") scrolls the content down, if possible
xscrollleft("appcobra") scrolls the content left, if possible
xscrollright("appcobra") scrolls the content right, if possible
xscrollreturntop("appcobra") returns the content to the top
xscrollback("appcobra") sends the content back one page in its history
xscrollforward("appcobra") sends the content forward one page in its history
xscrollreset("appcobra") resets the content of the inserted document to as it was
when loaded

Watching Accelerometer Events


Assuming you have selected the option Get Accelerometer Events in the App Settings dialog
box, the app will constantly check for accelerometer movements. Basically, it checks to see if
the device is being moved around at all.
This is checked very frequently to allow for quick responses. There are three JavaScript
variables that are constantly updated:

_kpmx (movement on the x axis)


_kpmy (movement on the y axis)
_kpmz (movement on the z axis)

So, you could add a routine in your app (using the Edit/Includes command) that reads
something like this:
var cm=setInterval('checkmovement()',20)
function checkmovement(){
currentxmovement=_kpmx*
}
*here you put any code you like. But you can reference any of the above variables to move or
respond in any way you like.
If you are using any of the moveme objects to be automatically moved around the screen, each
time they are moved, a routine called objectsmoved() is called. So, to respond to these objects
moving, you'd have to add this routine manually, using the Edit/Includes command:
function objectsmoved(){
//add your own code
}

Watching Geolocation Events


Assuming you have selected the option Geolocate in the App Settings dialog box, the app will
constantly check for the user longitude and latitude. Remember, the user is asked if they want
to allow this. If they say no, nothing is returned.
There are three variables related to user position that are updated as position is found, or
refined. These are:

geolocatex
geolocatey
geoaccuracy

geolocatex represents the user longitude, geolocatey represents the user latitude, and
geoaccuracy is a figure that represents how accurately the location was determined to.
Initially, geolocatex and geolocatey are set to the string 'Undetermined', until such time as
location is determined.
If there is any error determining location, or the user refuses the request, both values are set to
the string 'null'.

Writing Information to the User Machine


Many apps will require writing information to the user machine. This may be to record
preferences, save file information, any of a whole range of things.
Originally, cookies might have been used to do this. But, with the advent of HTML5, you can
now use offline storage to successfully store and retrieve much more information.
And it is dead easy.

Setting a Value
To save some content to a user machine, use this syntax:
xwritedata("myinfo", "Information I want to store")
In this example, the string "Information I want to store" is stored in a variable called
localstorage["myinfo"]. Unless the user specifically removes this from their machine, it will be
available any time the same page loads. So, when your app loads a subsequent time, you can
read this information again see below.

Retrieving a Value
Using the syntax:
theinfo= xreaddata(xname)
The variable called theinfo will be filled with the value stored under this variable see above.

Creating Dynamic Lists and Handling Results


Let's use an example to explain this one. We have an app, below, which allows user to answer
some questions. We then use the results to create a story:
This is a series of freeform text entry objects. The user fills in the details, and when they click on
Create Story, we check the values of the freeform text entry objects, using the getmxvalue
commands.
The app allows a series of stories to be saved to disk.
What we also allow is the user to be able to load, or delete stories that they have stored to disk.
So, essentially, when the app loads, we use the localstorage variables to read any stories
already saved to disk, and store this information in our own JavaScript variables and arrays.
What if we want to present the user with this list? We've made it a little easy for you.
On another page in the app, we create something that looks like this:
It just a series of text objects and graphics. The main text area, which reads [value of storylist]
is a text object. In this text object, we added the text:
%%%storylist%%%
This tells the app that this text object should be filled with the value of the JavaScript variable
called storylist. It is up to us to give this variable a value.
A simple example is this. Let's say this text object is called storylist.
var storylist="This is the new value" //this sets the value of the storylist variable
updatexobject('storylist') //this updates the content of the object called storylist.
But we need more than just a simple string here. We want to fill the storylist object with a list of
available stories.
Let us say that we keep the story names in a variable array called stories.
We can use a built in function called drawline to create a kind of dynamic index line:
drawline takes two parameters. One, is a string in our case, the name of the story. The
second is a number. This number allows you to identify the line in the index that will be the
result of future functions. We use the same number below as the number in the array.
storylist=""
for (jjj=0; jjj<stories.length; jjj++){
storylist=storylist + drawline(stories[jjj], jjj)
}
updatexobject('storylist')
The result might look something like this, as the app is running.
This dynamic index contains two lines. One is called My Second Story, and one is called Story
1.
On the right, two icons are automatically loaded. The first one, representing a kind of load
button, activates a routine called function listselected(t), where t equals the number of the item
selected. The second button, representing a delete function, activates a routine called
listdeleted(t), where 4 is the number of the item to be deleted.
So, by adding these routines to your app:
function listselected(t){
//check for value of t. This tells you the load button was clicked in what line
}

function listdeleted(t){
//check for value of t. This tells you the delete button was clicked in what line
}

Handling Audio
The following routines will only work for objects where audio has been loaded.
soundxduration(object)
Returns duration (milliseconds) of sound object
stopsoundx(object)
Stops sound playing of object.
pausesoundx(object, tao)
Pauses sound.
playsoundx(object)
Plays sound.
setsoundposx(object,xval)
Sets sound position in xval milliseconds of object
volumesoundx(object,xval)
Sets volume of audio object.

Forcing Flash Audio to Be Used


In the App Settings / App Settings command, there is an option called Include Flash Based
Audio. This creates a fallback Flash audio file for devices that do not support HTML5 audio
completely.
This can be used in the API. For example, if you use the App Settings / JavaScript Code and
Routines / HTML and JavaScript Code (Includes) command, you can enter (and it must be in
the top box, as whether Flash is used or not is decided by AppCobra before the code in the
lower box is executed):
<SCRIPT>
if (isie10==true&&iswin8==false){forceflash=true}
</SCRIPT>
The forceflash variable will force the app to use Flash based audio instead of HTML5 audio.
This should only ever be used conditionally, as devices like the iPhone and iPad will not play
Flash based audio at all.
The example above will force users of Internet Explorer 10, who are not using Windows 8, to
use Flash based audio instead of HTML5 audio.

Вам также может понравиться