Images

Create Image objects using the CreateImage function of the app object:

 img = app.CreateImage( file, width, height, options );

Use the SetOnTouch function of the Image object to set the name of a function you want to be called when the Image is touched.

When Image objects are touched, they send an event object parameter to your callback function which contains details of the touch event, for example the action property of the event object contains "Down", "Up" or "Move" as the user touches and moves their finger on the screen and the x and y properties contain arrays of touch coordinates.

If you don't set a size, the image object will match the original image size. If you set one dimension to a posotive value and leave the other dimension as -1, then the image will maintain its original aspect ratio. Specifying both width and height will stretch the image to fill the Image object, unless you can use the "ScaleCenter" option to keep the image at it's original size and centered within the Image object

Example - Original Size

function OnStart()
{
  lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

  img = app.CreateImage( "/sdcard/ioioscript/img/droid1.png" );
  img.SetOnTouch( img_OnTouch );
  lay.AddChild( img );

  app.AddLayout( lay );
}

function img_OnTouch( ev )
{
  if( ev.action=="Down" )
    app.ShowPopup( "Ouch!" );
}
  Copy   Copy All    Run   

Example - Stretched

function OnStart()
{
  lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

  img = app.CreateImage( "/sdcard/ioioscript/img/droid1.png", 0.5, 0.7 );
  img.SetOnTouch( img_OnTouch );
  lay.AddChild( img );

  app.AddLayout( lay );
}

function img_OnTouch( ev )
{
  if( ev.action=="Down" )
    app.ShowPopup( "Aaaargh!" );
}
  Copy   Copy All    Run   

Example - Maintain Aspect

function OnStart()
{
  lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

  img = app.CreateImage( "/sdcard/ioioscript/img/droid1.png", 0.5, -1 );
  img.SetOnTouch( img_OnTouch );
  lay.AddChild( img );

  app.AddLayout( lay );
}

function img_OnTouch( ev )
{
  if( ev.action=="Down" )
    app.ShowPopup( ev.x[0] + ", " + ev.y[0], "Short" );
}
  Copy   Copy All    Run