Hi,
i work on this for my megazine, in first time i did what you say florian but i have problem because i instantiate one eventListener by page and this cause problem...[/url]
What kind of problem, do you have a stack trace or something like that?
so i just let in my swf the function launch() and destroy() in the first frame, and i add an EventListener in main.as of megazine so i have just one listener for pageChange event...and if the page was not loaded i do an EventListener(Event.COMPLETE) with a callback function check if the page was visible... for access to the function launch() for the newPage and destroy() for the oldPage in my swf
i remove the error exception in pageSide.as when you try to access to getChildAt()..
Well, basically a feasible solution. Just one thing, regarding the getChildAt: I'll be rerouting that to the pluginLayer in the future releases,
mainly to avoid problems with loaded elements that think they have to parse the scene graph (and then crash when they hit the pageside).
To get access to elements on a page you should use the element proxies. Quick examples:
var ps:IPageSide = ...; // pageside containing the element you want
var proxy:IElementProxy = ps.elementProxies[2]; // 3rd element on the page (e.g. if you have
// <page><vid/><txt/><img/></page>
// that's be the img element.
// You probably won't be able to hardcode the number, though, so either
// loop through the elements to find the right one or use Ids (elementIds plugin)
var img:IImg = proxy.element as IImg; // Cast element to the actual type.
if (img) {
// Not null, so it's a) loaded and b) really an instance of Img
var swf
:DisplayObject = img.swf;
// Get the SWF object loaded by the Img element. }
and on my first swf page (cover) i let the code :
import de.mightypirates.megazine.interfaces.Constants;
import de.mightypirates.megazine.interfaces.IMegaZine;
import de.mightypirates.megazine.interfaces.IPageSide;
import de.mightypirates.utils.events.StateChangeEvent;
function megazineSetup(megazine:IMegaZine, pageside:IPageSide):void {
// Remember the pageside this element sits on to check visibility.
// Do a check if we're already visible (e.g. loading finished while current pageside was main page)
if (pageside.visible)
animateIn();
}
}
because when you load your megazine if you stay on the cover the pageChange Event was not dispatched..
Yeah, you won't get around that. Actually it'd be a good idea to have that on each page if you're using
SWFAddress (because the SWF on the page will most likely not be loaded at the time of the page turn).
Overall an OK solution, but in regards of upgradability you might consider putting what you added to the
Main.as into a plugin (so you're independent from changes I might do there -- although the Main.as will
probably not change in the next time anyway, so it's not that important).