Author Topic: Animatiing when page is visible using external class  (Read 257 times)

BillChristmas

  • Newbie
  • *
  • Posts: 2
Animatiing when page is visible using external class
« on: March 05, 2010, 11:08:06 AM »
Hello,

I've had a search through the forums and can't find an answer for this simple question.

I'm setting a page to play only when visible, placing the following code on the first frame of my fla -

Code: (actionscript3)
  1. import de.mightypirates.megazine.IMegaZine;
  2. import de.mightypirates.megazine.IPage;
  3. import de.mightypirates.megazine.elements.AbstractElement;
  4. import de.mightypirates.megazine.gui.ILibrary;
  5. import de.mightypirates.megazine.events.MegaZineEvent;
  6. import flash.display.MovieClip;
  7. var pageNumber:int;
  8. function megazineSetup(mz:*, ps:*):void {
  9. pageNumber = ps.number + (ps.number & 1);
  10. mz.addEventListener("page_change", handlePageChange, false, 0, true);
  11. }
  12.  
  13. function handlePageChange(e:*):void {
  14. if (e.newPage==pageNumber) {
  15. // Now main page
  16. play();
  17. } else if (e.oldPage == pageNumber) {
  18. // No longer main page
  19. stop();
  20. }
  21. }
  22.  

This works and behaves as expected, however I would prefer to put the code in an external class - my class is shown below:

Code: (actionscript3)
  1. package NewsLetter{
  2.  
  3. import de.mightypirates.megazine.IMegaZine;
  4. import de.mightypirates.megazine.IPage;
  5. import de.mightypirates.megazine.elements.AbstractElement;
  6. import de.mightypirates.megazine.gui.ILibrary;
  7. import de.mightypirates.megazine.events.MegaZineEvent;
  8. import flash.display.MovieClip;
  9. /**
  10. * ...
  11. * @author
  12. */
  13. public class BasicAnimatedPage extends MovieClip {
  14.  
  15. var pageNumber:int;
  16.  
  17. public function BasicAnimatedPage() {
  18.  
  19.  
  20. }
  21.  
  22. function megazineSetup(mz:*, ps:*):void {
  23.  
  24. pageNumber = ps.number + (ps.number & 1);
  25. mz.addEventListener("page_change", handlePageChange, false, 0, true);
  26.  
  27. }
  28.  
  29. function handlePageChange(e:*):void {
  30.  
  31. if (e.newPage==pageNumber) {
  32.  
  33. // Now main page
  34.  
  35. play();
  36.  
  37. } else if (e.oldPage == pageNumber) {
  38.  
  39. // No longer main page
  40.  
  41. stop();
  42.  
  43.  
  44. }
  45. }
  46. }
  47. }
  48.  

This is not working - I've tried to extend from an AbstractElement also but still doesn't work.

Any help would be much appreciated as this is driving me crazy.

Thanks!

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1342
  • MegaZine3 Developer
    • MegaZine3
Re: Animatiing when page is visible using external class
« Reply #1 on: March 05, 2010, 08:56:06 PM »
You'll probably have to explicitly declare the megazineSetup function as public, otherwise it won't be visible to the engine.
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.

BillChristmas

  • Newbie
  • *
  • Posts: 2
Re: Animatiing when page is visible using external class
« Reply #2 on: March 08, 2010, 10:51:50 AM »
Thanks a lot Florian. I'd presumed they were public by default.

Works great now.