Author Topic: Animate In and Out Sequences for Page Content  (Read 1146 times)

insultcomicdog

  • Newbie
  • *
  • Posts: 1
Animate In and Out Sequences for Page Content
« on: February 11, 2010, 10:45:56 pm »
Hey All,

I've pulled down the source from SVN, and have been trying to customize the flip book according to my specifications...

When a page has completed flipping I would like to initiate an Animate In sequence for the page content. I am loading in external swfs, which have public methods to animate in and out...

My question is, when and where in the Page or Magazine classes can I determine when the flip has finished animating so I can call Animate In functions on my page content?

Thanks In Advance,

SMJOHN


Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Animate In and Out Sequences for Page Content
« Reply #1 on: February 12, 2010, 09:33:12 pm »
You can completely do this in your SWFs, no need to change the engine files.

In your swf
Code: (actionscript3)
  1. import de.mightypirates.megazine.interfaces.Constants;
  2. import de.mightypirates.megazine.interfaces.IMegaZine;
  3. import de.mightypirates.megazine.interfaces.IPageSide;
  4. import de.mightypirates.utils.events.StateChangeEvent;
  5.  
  6. var myPageside:IPageSide;
  7. var wasVisible:Boolean = false;
  8.  
  9. function megazineSetup(megazine:IMegaZine, pageside:IPageSide):void {
  10.    // Register for state change events of the page this element sits on.
  11.    pageside.page.addEventListener(StateChangeEvent.STATE_CHANGE, handlePageStateChange, false, 0, true);
  12.    // Remember the pageside this element sits on to check visibility.
  13.    myPageside = pageside;
  14.    // Do a check if we're already visible (e.g. loading finished while current pageside was main page)
  15.    if (pageside.visible) {
  16.        wasVisible = true;
  17.        animateIn();
  18.    }
  19. }
  20.  
  21. function handlePageSideStateChange(e:StateChangeEvent):void {
  22.    if (e.newState == Constants.PAGE_STATE_READY) {
  23.        // Page animation stopped.
  24.        if (myPageside.visible && !wasVisible) {
  25.            // Now visible, and pageside wasn't visible before that, call your fade in function.
  26.            wasVisible = true;
  27.            animateIn();
  28.        } else {
  29.            // No longer visible, reset the state boolean here if the animation should
  30.            // be played every time the page side gets visible and animation stops.
  31.            // Otherwise remove this else block.
  32.            wasVisible = false;
  33.        }
  34.    }
  35. }
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

vincent

  • Full Member
  • ***
  • Posts: 61
Re: Animate In and Out Sequences for Page Content
« Reply #2 on: February 13, 2010, 12:49:45 pm »
hello,
(again sorry for my english)

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... you can see if you have a flash player debugger the trace action with flash tracer (firfox plugin) http://influenciatendance.net/

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()..

and on my first swf page (cover) i let the code :

Code: (actionscript3)
  1. import de.mightypirates.megazine.interfaces.Constants;
  2. import de.mightypirates.megazine.interfaces.IMegaZine;
  3. import de.mightypirates.megazine.interfaces.IPageSide;
  4. import de.mightypirates.utils.events.StateChangeEvent;
  5.  
  6. function megazineSetup(megazine:IMegaZine, pageside:IPageSide):void {
  7.   // Remember the pageside this element sits on to check visibility.
  8.   // Do a check if we're already visible (e.g. loading finished while current pageside was main page)
  9.   if (pageside.visible)
  10.       animateIn();
  11.   }
  12. }
because when you load your megazine if you stay on the cover the pageChange Event was not dispatched..
you can also see this version with this code on http://influenciatendance.net/test see the trace() action with flash tracer..

i can let me code here on monday

Florian, can you tell me what you think about this, is this a good solution ?

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Animate In and Out Sequences for Page Content
« Reply #3 on: February 14, 2010, 05:48:23 pm »
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:
Code: (actionscript3)
  1. var ps:IPageSide = ...; // pageside containing the element you want
  2. var proxy:IElementProxy = ps.elementProxies[2]; // 3rd element on the page (e.g. if you have
  3.                                                 // <page><vid/><txt/><img/></page>
  4.                                                 // that's be the img element.
  5. // You probably won't be able to hardcode the number, though, so either
  6. // loop through the elements to find the right one or use Ids (elementIds plugin)
  7. var img:IImg = proxy.element as IImg; // Cast element to the actual type.
  8. if (img) {
  9.    // Not null, so it's a) loaded and b) really an instance of Img
  10.    var swf:DisplayObject = img.swf; // Get the SWF object loaded by the Img element.
  11. }
  12.  

and on my first swf page (cover) i let the code :

Code: (actionscript3)
  1. import de.mightypirates.megazine.interfaces.Constants;
  2. import de.mightypirates.megazine.interfaces.IMegaZine;
  3. import de.mightypirates.megazine.interfaces.IPageSide;
  4. import de.mightypirates.utils.events.StateChangeEvent;
  5.  
  6. function megazineSetup(megazine:IMegaZine, pageside:IPageSide):void {
  7.   // Remember the pageside this element sits on to check visibility.
  8.   // Do a check if we're already visible (e.g. loading finished while current pageside was main page)
  9.   if (pageside.visible)
  10.       animateIn();
  11.   }
  12. }
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).
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.