My suggestion is enabling a more close-knitted integration between the API and the rest of the AS code. For example, at one point I had to get a reference to a loaded .swf page, and this is the code I had to use:
var currentPageSide:IPageSide
var pageTimeline:MovieClip = currentPageSide.elementProxies[0].element.interactiveObject.getChildAt(0).getChildAt(0)
And this returned me the swf timeline. I searched for hours in the API docs, forums and wiki, but this was the only way I found and took me quite some time to develop it.
Couldn't it be just
var currentPageSide:IPageSide
var pageTimeline:MovieClip = currentPageSide.getContent()
I don't want to tempt users to meddling with the actual elements on the page directly, as this could
easily break stuff. So that's why I won't expose the content directly. Still, it's not that complicated,
really. What you're doing implies you have a SWF loaded onto the page. To get access to those, do
something like this:
var yourSwf
:DisplayObject = IImg
(pageSide.elementProxies
[0].element
).swf;
Yes, you still need to go through the proxies, but that's necessary because elements can be unloaded.
Secondly, yes you'll need the index, because, after all, there can be any number of elements on a page
(which is why a simple getContent isnt' really doable, either -- well, it could always just return the first
element on the page, but that's kinda...).
Note that that only is true for elements defined via the XML, though. I added a possibility to add elements
to pagesides directly in the last commit (will be in 2.0.6), so you could just add your element to a page side
and work with those, then. To that "layer" you'll have direct access (via treating a pageside like a normal
DisplayObjectContainer). More on that below.
And for the book settings, why not
megazine.autoDrag = false
instead of setting it via XML?
Or, if it's not a good idea to change settings during runtime, make a load method that accepts a "MegaZineConfiguration" object...
That's actually one of the parameters that could be changed afterward. Reason it's not changable via the API is because I didn't really think
it to be necessary, because normally you'd not change that during runtime (but once, in the XML). As for that config object, see below.
And why does the "megazine.addPage" method requires an XML object and not a class name or generator function?
I know there is the plugin layer, but it only works as a temporary solution, lost as soon as the page needs to be unloaded.
I get the feeling you don't like the idea of defining things in XML?

Elements that should be unloaded / reloaded with the page must be defined in the XML (mainly so that they can be reloaded
once removed). And that's the default way of constructing a book. To add content manually, see below, I just added this, as
there seems to be some demand for this. Note that displayobjects added to a page this way cannot be unloaded / reloaded
by the engine, though.
All this interactions are probably already there, but covered by a thick layer of bureaucracy. The following is a mockup code of what I really needed from this API:
var configuration:MegaZineConfiguration = new MegaZineConfiguration()
configuration.autoDrag = false
configuration.maxLoaded = 25
var megazine:MegaZine = new MegaZine(configuration) // or via a tweenlite-like object: { autoDrag: false, maxLoaded: 10 }
addChild(megazine)
megazine.load() // loads all that visual assets required, such as asul files and cursor icons
var pageGenerator(pageNumber:int):MyPage {
var page:MyPage = new MyPage(pageNumber) // MyPage can implement an IPage interface or be wrapped by a Page instance when added to the book
return page
}
megazine.addPage(MyCover) // MyCover is a class that would be instantiated every time this page had to be loaded
megazine.addManyPages(pageGenerator, 40) // the function is called every time a new page has to be loaded, and the "pageNumber" parameter is passed as in the array.map method
And then you have a megazine instance with a cover and 40 dynamically generated pages, all using only ActionScript.
If there is already a way to do the above, please let me know. I'm still pulling hairs here.
When using the latest revision in the trunk, you could do this:
var megazine:IMegaZine = new MegaZine();
addChild(megazine);
megazine.
addEventListener(Event.
COMPLETE, handleMZComplete,
false,
0,
true);
megazine.loadXML(null, null, { autodrag : false, maxloaded : 25 }); // < new in the latest revision, allows passing
// parameters that override definitions in the XML
function handleMZComplete
(e
:Event):void { for (var i
:int =
0; i
< 40; i
+=
2) { var page:IPage = megazine.addPage();
DisplayObjectContainer(page.even
).
addChild(yourContentGenerator
(i
));
// Also new in the latest revision, adding like this DisplayObjectContainer(page.odd
).
addChild(yourContentGenerator
(i
+ 1));
// will now add to a special layer where the content // will not be removed on unloading a page.
}
}
// returns some displayobject for page 'pageNumber'
}
Note that elements this way will always be on top of elements defined in the book's XML, and below the pluginLayer.
They will not be unloaded if the page is unloaded.