Skip to content

Serialized Objects

Compiling the scripts protects your code, but the objects on your pages still sit in the project for anyone to look at: their text, their list items and their settings. With serialized objects, the module creates the objects at run time instead, and they're removed from the rewritten project.

a2c build MyProject.autoplay --serialize-objects --tab-order

In the application, you'll find these settings on the Objects page.

How It Works

For each page or dialog with objects to create, the module gets one more function. The page's On Show event calls it first, before its own code runs. That function creates every object with Page.CreateObject (or DialogEx.CreateObject on a dialog), with the same properties the project gave it, and hooks up its event scripts:

Page.CreateObject(7, "Name", { -- 7 is OBJECT_INPUT
    Text = "",
    FontName = "Segoe UI",
    FontSize = 9,
    -- and every other property of the object
});
Page.SetObjectScript("Name", "On Key", "core.f6(this, e_Key, e_Modifiers);");
ListBox.AddItem("Choices", "One", "1");

The object's own event scripts are compiled just like every other script. List box and combo box items, tree nodes, checked items and a grid's file come along with the object.

What Stays in the Project

What Why
Object plugins A script can't create them, so they always stay.
Kinds you exclude For instance all inputs. Use --exclude-kind input,listbox or the check boxes in the application.
Objects you exclude Named as Page::Object, for instance --exclude-object "Main::Logo".

Kinds are named after their action library, in any case: button, label, paragraph, image, flash, video, web, input, hotspot, listbox, combobox, progress, tree, radiobutton, richtext, checkbox, slideshow, grid, pdf, quicktime and xbutton. The OBJECT_ constants (OBJECT_INPUT) and their numbers (7) work too.

What Changes for Your Application

Serialized objects behave like the originals, but there are a few differences you should know about:

  • Objects exist from On Show on. A page's On Preload can't reach them yet, so move code that works with objects from On Preload to On Show.
  • They're drawn on top. Created objects come in the order of the project, but above the objects that stay in the project.
  • A few settings have no property. A script can't set them, so a created object goes without them: a tree's indent, a rich text object's automatic word selection, a QuickTime object's full screen settings, and the alternate image of web and Flash objects. In a right-to-left project, a tree set to read left to right reads right to left.
  • Text is Windows-1252. A character that this code page doesn't have becomes ?, and autoplay2c warns you about it.

Tab Order

Objects that are created at run time don't have a place in the page's tab order, so pressing Tab skips them. --tab-order (Emulate the tab order in the application) fixes that on pages with serialized objects:

  • Tab moves the focus to the next control, and Shift+Tab to the previous one.
  • Controls are inputs, list boxes, combo boxes, check boxes, radio buttons, rich text objects, trees, grids and xButtons.
  • From anywhere else, Tab goes to the first control and Shift+Tab to the last.

The order follows the order of the objects in the project, in reverse, just like the previous version of autoplay2c did it.

Warning

The emulation runs in On Key events. Check boxes, radio buttons, xButtons and grids don't have an On Key event, so you can tab to them, but not out of them.

Checking the Result

Serialized objects are new to many projects, so it's worth checking that nothing was lost. The probe command makes a copy of your project that logs every object's properties when a page is shown. Compare the log of the original with the log of the build, and you'll see exactly what differs.

Technical details
  • Property names follow the GetProperties and SetProperties tables of the AutoPlay Media Studio help, per object kind.
  • Colours stored as hexadecimal rrggbb become the numbers scripts use (0x00BBGGRR, as Math.HexColorToNumber returns). Font heights become point sizes, rounded as the designer rounds them.
  • Page.CreateObject doesn't read every property its object's SetProperties reads, and reads a few of them wrongly. autoplay2c sets those with SetProperties once the object exists: a button's margins, a check box's resize edges, a label's size, the kind of a list box, and the reading order of inputs, list boxes, combo boxes and trees.
  • A grid shows the colours it's created with only when they come from the project, so custom colours are set with Grid.SetProperties. A grid's file is loaded after its settings, or before them with the settings applied again, as the project says.
  • The generated code is ordinary module code: it's compiled, the data folder is replaced in its strings, and its diagnostics name the page as page/Main/(objects).