Author Topic: Getting SWFs to play only when page is shown  (Read 2462 times)

cduchesne

  • Newbie
  • *
  • Posts: 21
Re: Getting SWFs to play only when page is shown
« Reply #15 on: October 27, 2009, 10:18:11 PM »
yay! That's it!!
Thank you!

shipoopi

  • Newbie
  • *
  • Posts: 2
Re: Getting SWFs to play only when page is shown
« Reply #16 on: November 04, 2009, 05:22:43 PM »
Really like your program!  Can you tell me where to put this code? I don't know action script, but know how to copy and paste it into a keyframe. Is that what should be done with this? Copy and paste it into the first keyframe in my .fla file?  Then when the swf is published and uploaded for showing in my megazine it won't play until the page is actually fully turned? Thanks for ur help  :)



@cduchesne: this is expected behavior, nothing to fix there. It is visible, after all. I understood the problem james described more as a depth sorting issue. To do what you want, i.e. only do something if the page is the current "main" page, try this:
Code: (actionscript)
  1. // yadayada imports
  2.  
  3. var pageNumber:int;
  4. function megazineSetup(mz:IMegaZine, ps:IPageSide):void {
  5.    pageNumber = ps.number + (ps.number & 1); // get even number of the double page this page side belongs to
  6.    mz.addEventListener(PageChangeEvent.PAGE_CHANGE, handlePageChange);
  7. }
  8.  
  9. function handlePageChange(e:PageChangeEvent):void {
  10.    if (e.newPage == pageNumber) {
  11.        // Now main page
  12.    } else if (e.oldPage == pageNumber) {
  13.        // No longer main page
  14.    }
  15. }


Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1413
  • MegaZine3 Developer
    • MegaZine3
Re: Getting SWFs to play only when page is shown
« Reply #17 on: November 05, 2009, 06:57:55 PM »
Code: (actionscript)
  1. var pageNumber:int;
  2. function megazineSetup(mz:*, ps:*):void {
  3.    pageNumber = ps.number + (ps.number & 1);
  4.    mz.addEventListener("page_change", handlePageChange, false, 0, true);
  5. }
  6.  
  7. function handlePageChange(e:*):void {
  8.    if (e.newPage == pageNumber) {
  9.        // Now main page
  10.        play();
  11.    } else if (e.oldPage == pageNumber) {
  12.        // No longer main page
  13.        stop();
  14.    }
  15. }

This should go into the script block of the first frame of a separate timeline layer (extra timeline layer so that it won't be "ignored" at some later point on the timeline). Note that I removed all typing to keep you from having to fetch the sources from the SVN repo.

Further Note to anyone else using this: just realized the event listener could cause memory leaking issues, change it accordingly like here (make it a weak reference on the listener).
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.

hanzc

  • Newbie
  • *
  • Posts: 10
Re: Getting SWFs to play only when page is shown
« Reply #18 on: November 12, 2009, 05:19:20 PM »
Does it work, anyone?

It doesn't work for me.

It seems that the functions aren't being called at all.

I've modified the codes to include trace messages as follows:

---------------------------------------------------------------------------------------------------------------------
var pageNumber:int;
function megazineSetup(mz:*, ps:*):void {
   trace ("i am here");
    pageNumber = ps.number + (ps.number & 1);
    mz.addEventListener("page_change", handlePageChange, false, 0, true);
}
 
function handlePageChange(e:*):void {
 trace ("i am there");
    if (e.newPage == pageNumber) {
        // Now main page
//        play();
      for (var i = 0; i < particlesArray.length; i++) {
         var particle = particlesArray;
         particle.y += particle.speedY;
         particle.x += particle.speedX;
   
         //If the particle is below the bottom, position it back to the top
         if (particle.y > stage.stageHeight) {
            particle.y = 0;
            particle.x = Math.random() * stage.stageWidth;
         }
      }

    } else if (e.oldPage == pageNumber) {
        // No longer main page
        stop();
    }
}
---------------------------------------------------------------------------------------------------------------------
The result in the console shows:

Type "help" for command listing.

** [00:17:12] [   MegaZine    ] System:  MegaZine Version 2.0.1 initializing...
** [00:17:12] [   MegaZine    ] Notice:  Begin loading XML data from file 'http://lo...zine.mz3?r91234639=47067836'.
** [00:17:12] [   MegaZine    ] Notice:  Parsing settings: step 1 (engine settings).
** [00:17:12] [   Settings    ] System:  Disabling notices.


Nothing was printed at all.

Please help. (Urgent)

Mike

cduchesne

  • Newbie
  • *
  • Posts: 21
Re: Getting SWFs to play only when page is shown
« Reply #19 on: November 12, 2009, 05:26:16 PM »
have you imported everything you need?

import de.mightypirates.megazine.interfaces.IPageSide;
import de.mightypirates.megazine.events.PageChangeEvent;

and i've found it can help to create another instance of Megazine:

var mz2:IMegaZine;

function megazineSetup(mz:IMegaZine, ps:IPageSide):void {
   mz2 = mz;
   pageNumber = ps.number + (ps.number & 1); // get even number of the double page this page side belongs to
   mz2.addEventListener(PageChangeEvent.PAGE_CHANGE, handlePageChange, false, 0, true);
}

hanzc

  • Newbie
  • *
  • Posts: 10
Re: Getting SWFs to play only when page is shown
« Reply #20 on: November 12, 2009, 05:41:41 PM »
hmm....

By doing the imports, does it mean that I have to grab the source out from SVN and compile it?

The reason why I chose to use the following codes is that I want to save the hassle to do the source file retrieval.

function megazineSetup(mz:*, ps:*):void {
    pageNumber = ps.number + (ps.number & 1);
    mz.addEventListener("page_change", handlePageChange, false, 0, true);
}


The Types are all *.

Thanks

cduchesne

  • Newbie
  • *
  • Posts: 21
Re: Getting SWFs to play only when page is shown
« Reply #21 on: November 12, 2009, 05:46:11 PM »
yes you do...

hanzc

  • Newbie
  • *
  • Posts: 10
Re: Getting SWFs to play only when page is shown
« Reply #22 on: November 12, 2009, 06:01:15 PM »
But based on what Florian Nücke had said, I should not need to retrieve it from source:

Code: (actionscript)
  1. var pageNumber:int;
  2. function megazineSetup(mz:*, ps:*):void {
  3.    pageNumber = ps.number + (ps.number & 1);
  4.    mz.addEventListener("page_change", handlePageChange, false, 0, true);
  5. }
  6.  
  7. function handlePageChange(e:*):void {
  8.    if (e.newPage == pageNumber) {
  9.        // Now main page
  10.        play();
  11.    } else if (e.oldPage == pageNumber) {
  12.        // No longer main page
  13.        stop();
  14.    }
  15. }

This should go into the script block of the first frame of a separate timeline layer (extra timeline layer so that it won't be "ignored" at some later point on the timeline). Note that I removed all typing to keep you from having to fetch the sources from the SVN repo.

Further Note to anyone else using this: just realized the event listener could cause memory leaking issues, change it accordingly like here (make it a weak reference on the listener).

So it doesn't work?

I really have to go into SVN to download the source, setup ant and paths.... bla bla bla.... Ouch ... painful...


:(

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1413
  • MegaZine3 Developer
    • MegaZine3
Re: Getting SWFs to play only when page is shown
« Reply #23 on: November 12, 2009, 06:46:39 PM »
You only need the imports (and thus the sources) if you want the actual types (e.g. the interfaces), but using the generic * instead of the actual type works, too.

Now, as for the trace: traces won't show up in the console, there's no way I can catch those... to display stuff in the console you'd need to use the Logger class (but then you'll need the sources again).

Easiest thing to check it would probably to paint a colored rectangle somewhere if the function is called :P
Code: (actionscript3)
  1. // This inside the megazineSetup
  2. graphics.beginFill(0xFF0000);
  3. graphics.drawRect(0,0,100,100);
  4. graphics.endFill();
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.

cduchesne

  • Newbie
  • *
  • Posts: 21
Re: Getting SWFs to play only when page is shown
« Reply #24 on: November 18, 2009, 12:08:18 AM »
my problem with this now is my first page. As the new page comparison can't apply to the first page, I need to just make the animations and sounds play in the swf, since they have to play automatically.

If the users later returns to the first few pages, megazine loads up this first page in order to have a few pages before and after ready, as it should. However, when the user arrives at page 3 for instance, you can hear the sounds from that first page because it doesn't have visibility script to stop it from playing.

Is there other javascript to detect whether a page is truly visible or not?

thanks!

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1413
  • MegaZine3 Developer
    • MegaZine3
Re: Getting SWFs to play only when page is shown
« Reply #25 on: November 18, 2009, 08:24:19 AM »
I think I wrote this in another thread... gimme a sec... here it is:
http://megazine.mightypirates.de/forum/index.php/topic,660.0.html

Change accordingly in first page, should solve your problem (so you don't have to start it "blindly").
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.

cduchesne

  • Newbie
  • *
  • Posts: 21
Re: Getting SWFs to play only when page is shown
« Reply #26 on: November 18, 2009, 05:38:24 PM »
thanks!

but since it's the first page and the first time we see it it's not happening with a page change, it required code to start it anyway.

handlePageChange calls onPageVisible.
 
function megazineSetup(mz:IMegaZine, ps:IPageSide):void {
      pageNumber = ps.number + (ps.number & 1);
      mz.addEventListener(PageChangeEvent.PAGE_CHANGE, handlePageChange, false, 0, true);

      if(mz.currentLogicalPage == 0){
         onPageVisible();
      }
      
   }