Moscrif API Docs for: 2012q3
Show:

System Class

Library: core

This class represents underlying system.

Methods

copyFile

(
  • source
  • destination
  • [overwrite=false]
)
Boolean

Copy source file to destination. If destination file exists and owerwrite is true function rewrites the file.

Parameters:

  • source String

    Source file.

  • destination String

    Destination.

  • [overwrite=false] Boolean optional

    Determines what happen when destination file exists. If destination file exists and owerwrite is true function rewrites the file. If overwrite is false function fails. default: false.

Returns:

Boolean: True if function succeed, otherwise returns false.

Example:

    System.copyFile("dat://source.txt", "dat://destination.txt");

createDir

(
  • dir
  • [createSubDirs=false]
)
Boolean

Creates directory

Parameters:

  • dir String

    Location and name of new directory If directory exists function returns false.

  • [createSubDirs=false] Boolean optional

Returns:

Boolean: True if function succeed, otherwise returns false

Example:

var location = System.path(#USER_DOCUMENTS);
if (!System.isDir(location+"/newFolder"))
    System.createDir(location+"/newFolder");  //create new folder in directory, where user's documents are saved usually
else;
    // this folder alredy exists

deleteDir

(
  • dir
)
Boolean

Delete directory / folder. Folder have to be empty.

Parameters:

  • dir String

    Location of directory / folder to delete. If directory does not exist function returns false.

Returns:

Boolean: True if function succeed.

Example:

    var location = System.path(#USER_DOCUMENTS);
    if (System.isDir(location+"/newFolder"))
        System.deleteDir(location+"/newFolder");  //delete folder in directory, where user's documents are saved usually
    else;
        // this folder does not exists

deleteFile

(
  • file
)
Boolean

Delete file.

Parameters:

  • file String

    Location of file to delete. If file does not exist function returns false

Returns:

Boolean: True if function succeed.

Example:

var location = System.path(#USER_DOCUMENTS);
if (System.isFile(location+"/userFile.txt"))
    System.deleteFile(location+"/userFile.txt");  //delete file from directory, where user's documents are saved usually
else
    // this file does not exists

exec

(
  • cmd
  • [args]
  • [dir]
)
Boolean

This functions manages some system operations like mail or sms sending, calling, pictures taking etc.

Parameters:

  • cmd Object

    Use module name (command line) or Available commands:

    • "call-to"
    • "mail-to" - send mail
    • "sms-to"
    • "take-image" - takes a photo using the camera
    • "show-image" - show image in built-in image viewer
    • "record-video" - record video; parameter file: is overwriten if exists, callback: function which accept maximum of one parameter (location of taken video)
    • "play-video" - play video in default video player
    • "open-url" - open url in web browser
  • [args] String optional

    Command line arguments.

  • [dir] String optional

    orking directory.

Returns:

Boolean: True if function succeed

Example:

// "call-to"
System.exec ({
    command: "call-to",
    phone: "00421954444333";

});

//"mail-to"
System.exec ({
    command: "mail-to",
    to: "",
    cc: "carbon copy",
    bcc: "blind carbon copy",
    subject: "mail subject",
    body: "text of mail",
});

//"sms-to"
System.exec ({
    command: "sms-to",
    to: "00421954444333",
    text: "message text",
});

//"take-image"
var callBack = function(file)
{
    console<<file<<"\n"; // returns image location
}
System.exec({
    command: "take-image",
    file: "dat://image.jpg",
    callback: callBack,
});

//"show-image"
System.exec({
    command: "show-image",
    file: "dat://image.jpg",
});

getFileSize

(
  • file
  • destination
  • [overwrite]
)
Integer

Returns size of file in bytes.

Parameters:

  • file String

    File location

  • destination String

    Destination.

  • [overwrite] Boolean optional

    Determines what happen when destination file exists. If destination file exists and owerwrite is true function rewrites the file. If overwrite is false function fails. default: false.

Returns:

Integer: Size of the file.

Example:

var location = System.path(#USER_DOCUMENTS);
if (System.isFile(location+"/userFile.txt"))
    console<<"File size: " << System.getFileSize(location+"/userFile.txt") << "B\n";
else
    // this file does not exists

hideKeyboard

()

Hide system (build-in native) keyboard.

Example:

    // system keyboad is not supported in emulator
    if(System.IS_EMULATOR === false)
        System.hideKeyboard();

home

() String

Function returns home of the current application.

Returns:

String: Location of application file

isDir

(
  • dir
)
Boolean

Checks, if directory / folder (sets by parameter) exists.

Parameters:

  • dir String

    Directory location to check.

Returns:

Boolean: True if directory / folder exists, otherwise returns false.

Example:

System.isDir("dat://folder/subfolder"); // returns true if subfolder exists

var location = System.path(#USER_DOCUMENTS);
if (!System.isDir(location+"/newFolder"))
    System.createDir(location+"/newFolder");  //create new folder in directory, where user's documents are saved usually
else;
    // this folder alredy exists

isFile

(
  • file
)
Boolean

Checks, if file (sets by parameter) exists.

Parameters:

  • file String

    SPath to file to check existance

Returns:

Boolean: True if file exists, otherwise returns false

Example:

System.isFile("dat://folder/a.txt"); // returns true if file exists

var location = System.path(#USER_DOCUMENTS);
if (System.isFile(location+"/userFile.txt"))
    System.deleteFile(location+"/userFile.txt");  //delete file from directory, where user's documents are saved usually
else;
    // this file does not exists

messageBox

(
  • fmessage
)
Boolean

Displays a modal dialog box that contains text and OK button.

Parameters:

  • fmessage String

    Text to be displayed in the dialog box

Returns:

Boolean: True when user click to the button

Example:

var location = System.path(#USER_DOCUMENTS);
if (System.isFile(location+"/userFile.txt"))
    console<<"File size: " << System.getFileSize(location+"/userFile.txt") << "B\n";
else
    System.messageBox("this file does not exists");

path

(
  • folder
)
String

Creates path to the required folder. F.e.: folder with user documents, program files etc. This folders can be placed diferents on diferent platforms.

Parameters:

  • folder Symbol

    Specification of folder

    • #SYSTEM
    • #SYSTEM_BIN
    • #PROGRAM_FILES
    • #USER_APPDATA
    • #USER_HOME
    • #COMMON_APPDATA
    • #USER_DOCUMENTS
    • #COMMON_DOCUMENTS

Returns:

String: Path to required folder

Example:

// get location of “my documents” folder
var location = System.path(#USER_DOCUMENTS);
if (System.isFile(location+"/userFile.txt"))
    System.deleteFile(location+"/userFile.txt");  //delete file from directory, where user's documents are saved usually
else;
    // this file does not exists

requestKeyboard

(
  • callback
  • keyboardType
)
Boolean

Displays system (build-in native) keyboard.

Parameters:

  • callback Function

    Callback function.

  • keyboardType Symbol
    • #default
    • #email
    • #web
    • #pin
    • #phone

Returns:

Boolean: True when system keyboard is available.

Example:

function processKey(sender, key)
{
    console << "key on keyboard: " << key << "\n";
}
if (!System.requestKeyboard(processKey, #default)) {
    // use software keyboard
    // swKeyboard = new Keyboard();
    swKeyboard.visible = false;
}

resetApplicationData

() Boolean

Resets application's data. (Android only).

Returns:

Boolean: True if function succeed, otherwise returns false

scanFiles

(
  • path
  • [ef]
)
Integer

This function tries to find all files in required format at specified location.

Parameters:

  • path String

    Folder, inside which we want to search and also format of required files f.e.: "dat://folder/*.txt".

  • [ef] Function optional

    Function, which is called for each found file. This function should accept two parameters (name of file and file flag) and returns true for continue searching or false for stop searching.

Returns:

Integer: Number of found files.

Example:

function manage(name, flag)
{
    console<<"file name: "<<name<<" flag: "<<flag<<"\n";  // displays information about file
    return true;    // search for another file (return false for stop searching)
}
System.scanFiles("dat://folder/*.txt", manage); //search for txt files in dat://folder/ returns number of files

Properties

applicationId

String

Returns application's unique identifier.

avgFPS

Float

Avarage number of frames per second.

avgRender

Float

Average render time in ms.

country

String

The country (or the region) name, based on ISO Standard 3166.

deviceId

String

Returns device's unique identifier

height

Integer

Height of the device screen

IS_DEBUG

Boolean

True if application is currently in debug mode.

IS_DIR

Integer

Flag used for directories.

IS_EMULATOR

Boolean

True if application runs in emulator.

IS_HIDDEN

Integer

Flag used for hidden files and directories.

IS_READONLY

Integer

Flag used for read-only files.

IS_RT_DEBUG

Boolean

True for debug version of Moscrif run-time.

IS_SYSTEM

Integer

Flag used for system files and directories.

IS_TABLET

Boolean

True if aplication runs on tablet.

language

String

Returns the abbreviated name of the language, ISO Standard 639 names. List of ISO 639-1 code is available here: http://en.wikipedia.org/wiki/ListofISO639-1codes

maxFPS

Float

Maximum number of frames per second.

maxRender

Float

Maximum render time in ms.

minFPS

Float

Minimum number of frames per second.

minRender

Float

Minimum render time in ms.

OS_NAME

String final

Gets the device's operating system. Following symbols can be returned:

  • #Windows
  • #Mac
  • #linux
  • #iOS
  • #Android
  • #bada* #Symbian

publicKey

String

Returns Moscrif's RSA public key.

tick

Integer

Number of miliseconds. This property is suitable for animation (game) scheduling.

width

Integer

Width of the device screen