WebKit is also the engine of choice for Apple's Safari Web browser (in fact, for Apple's operating system as a whole). An HTML page that looks and functions like you want it to in Safari will reliably look and function the same as an AIR application. (Even though Safari is made by Apple, it also now runs on Windows.)
Object-oriented programming (OOP) is a serious subject that requires years of experience and learning to master. This book doesn't teach OOP, but that's not a problem, because you can easily use OOP without any mastery at all. The premise of OOP is as follows.
You first define a class, which is a blueprint that maps out the variables and functions required to work with a certain thing. For example, a blueprint of a rectangle would have variables that store its length and width. It would also have functions that calculate its perimeter and its area. Confusing matters just a little bit, the variables in a class are normally called attributes or properties, and the functions are normally called methods.
To use a class, you can create a variable of that class type using the new keyword:
var r = new Rectangle();
Now the r variable is an object of type Rectangle (r is called an instance of Rectangle). To access the object's attributes and methods, use the dot syntax:
r.length = 20; var a = r.getArea(); // Call the method.
First, you won't always create an object initially. Some class functions can be used without creating an object, and some objects are created automatically for you. For example, a Web browser, or AIR HTML page, starts with a document object.
document.getElementById('thing').className = 'newClassName';
This code starts by calling the getElementById() method of the document object. That method returns an element in the page that matches the given ID (thing in this example). Then the className attribute of the thing element is assigned a new value (of newClassName). This is just a shortcut way of writing:
var thing = document.getElementById('thing'); thing.className = 'newClassName';
- File system access
- Working with sounds and images
- Working with the computer's clipboard
- Interacting with databases
var fp = new window.runtime.flash.filesystem.File();
Of the many new concepts you'll need to learn to fully adapt your existing Web development knowledge to creating desktop applications, none is more important than security. The Web browser has its own security model: Web pages are quite limited in what they can do with respect to the user's computer. Since AIR applications behave like standard programs, the rules are significantly different.
The AIR security model uses the concept of sandboxes: the realm in which an application can "play," which is to say where it can read data from or write data to. AIR builds on the Flash security model, which defines two sandboxes: one for the local filesystem (i.e., the user's computer) and another for remote computers (i.e., the Internet, other networked computers, etc.). AIR adds to these a third sandbox—application—which refers to the files and content that reside in the application's folder.
For example, the user installs an AIR application. When that program runs, it loads the main HTML page. This is the application sandbox. If that program retrieves content from the user's computer (i.e., from another directory), that's the local sandbox. If the program loads content from a Web site, that's the remote sandbox. The distinctions are important because they affect what a program can do with the content, as well as what security measures need to be taken. This topic is thoroughly covered in Chapter 15, "Security Techniques."
Universal Resource Identifiers
One of the most basic terms any Web developer knows is URL, which stands for Uniform Resource Locator (it used to mean Universal Resource Locator). If you want someone to access your site, you provide them with a URL, such as http://www.example.com. The http:// part of the URL is the protocol; common alternatives are https:// and ftp://. The www.example.com is the address; although, an IP address can also be used.
Naturally, your Adobe AIR applications will use URLs, but not every resource in an AIR application will be found online. Along with http://, https://, and ftp://, AIR supports:
(There's also a plan to support feed:// and mailto:// in future versions of AIR.) Taken together, these are all Universal Resource Identifiers (URIs).
As you may already know, file:// is supported by the Web browser, too, as a way to open local or networked documents. But the other two listed URIs are new to Adobe AIR. The first, app:/ (notice there's only one slash), always refers to the directory where the AIR application is installed: the application's root. If you create an application whose main file is called index.html, no matter what operating system that application is installed on or where the user chose to install it, app:/index.html points to that main page. The second new URI, app-storage:/ (again, one slash), refers to the application's storage directory, which will be a folder on the user's computer, different than the application's root directory.
From a security perspective, content within app:/ has full privileges. In other words, this content can do the most harm to the user's computer! Any content an application loads from app-storage:/, http://, and the others, is more limited as to what it can do.