JSON: In the standard HTML/CSS world, JavaScript is used to add logic and create more complicated interaction within a document. In Wrapper you can't really use javaScript in the same way. You can call javascript methods but the preferred way to do things is using a combination between JavaScript Object Notation (JSON) and compiled ActionScript 3 plugins. Actionscript 3 is actually an advanced version of the next unreleased version of JavaScript both based on ECMA Script. This document will explain the different ways that JSON is used in Wrapper and how to make your own plugins. Where JSON is used: The biggest use for JSON in Wrapper is for calling methods, these methods can have specific method signatures that are baked into Wrapper itself or part of your custom plugin. The simpler versions of this are used in CSS. .myClassStyle { shape: json('{"type":"box"}'); } This is a simple function call saying that the same of any element that this style is applied to will have it's shape be a box. This is very simple but the set up enables more complex called with specific data type inside like this: .myClassStyle { fill: json('{"type":"gradient","kind":"linear","colors":[0,16000000],"alphas":[1,1],"ratios":[0,255],"w":1,"h":1, "r":0,"tx":0,"ty":0}'); } In this example anything with this style defined will have a complex gradient fill from black to white. The colors are defined as arrays(list of values [0,1]) and the parameters themselves are all in an object defined by curly braces. Each of these methods in CSS has there own method signature and which is more defined in the CSS documentation. Using external JSON files: Because these JSON method calls can become quite long you can also move them to external files. Here's an example of the set up. The JSON file can be called anything but for this example, open any text editor and make a file called "objects.json". Inside of this file write this. { // JSON Objects file http://0in1.com/wrapper/ ver.1 "actions": { "myMethod": { "type":"instance", "class":"flash.display.Sprite", "method":"startDrag", "args":[ true ] } }, "fill": { "black2white": {"type":"gradient","kind":"linear","colors":[0,16000000],"alphas":[1,1],"ratios":[0,255],"w":1,"h":1, "r":0,"tx":0,"ty":0} } } As you can see in this file we have a custom action given the name "myMethod", all custom methods will go into this actions object. Below this there is a fill object that has the same fill that we described above but associated with the name "black2white". Objects can be made for any property that excepts JSON. The names that are given to these objects is called by your HTML or CSS files. But before we can do that the JSON file itself needs to be loaded, to do that place this in the head of your html next to your other link tags. And then in your HTML and CSS you can call these methods by just calling there names. HTML example:
CSS example: .myClassStyle { fill: json('black2white'); } These objects are reusable and can be associated with multiple elements and styles. Making custom function calls: A custom method call still has a structure that has to be confined to. All custom methods have a type, the options are; javascript, singleton, class, instance, static, or document and are formated something like this. { "type":"instance", "class":"flash.display.Sprite", "method":"startDrag", "args":[ true ] } JavaScript methods call any JavaScript method that has previously been included in your current document. Singleton methods methods that can only be instantiated once and reference is made through a method called getInstace() Class methods are methods that are called through their constructor. Instance methods are need to be called on an instance of the objects themselves Static methods have the static keyword and are call on objects directly Document methods are methods that are within Wrapper being called on the document This is a very broad overview and we suggest buying a copy of Moock's ActionScript 3 book to get you started if you dont know what any of this means. Here is an example of a Static method and a document method call, a custom plugin and how to tie it all together. In your html file make something like this.