Author Topic: Is it possible to replace individual pages once the book is loaded?  (Read 1542 times)

kongo09

  • Jr. Member
  • **
  • Posts: 43
Once the book is loaded and displayed, I'd like to know if I can replace pages (e.g. the cover) without reloading the whole book. This would need to be initiated from the outside (e.g. by Javascript).

kongo09

  • Jr. Member
  • **
  • Posts: 43
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #1 on: November 20, 2009, 01:55:33 pm »
Or: is it possible to tell the Flash application via Javascript to discard the current book, grab a fresh .mz3 file and display the new content?

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1989
  • MegaZine3 Developer
    • MegaZine3
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #2 on: November 20, 2009, 10:09:29 pm »
Dynamic page removal is still... let's call it "experimental". Meaning I've never really tested it. But there are functions in the API which allow you to remove (and add; at least the adding works ;)) pages at runtime.

You'll have to look at the actual MegaZine class, not the interface, though (not in there yet because of said untestedness). Making that accessible via JS is just a matter of adding an ExternalInterface callback somewhere where you have access to the MegaZine instance (e.g. the Main class).
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.

kongo09

  • Jr. Member
  • **
  • Posts: 43
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #3 on: November 23, 2009, 12:30:49 am »
Hm, I guess that's a bit over my head. I've never done anything in flash.

Should a Javascript call to reload the .mz3 (and consequently to reload the book if the .mz3 has changed in the meantime) make it into one of the future releases, I'd be quite happy. Maybe reloading everything is also easier and more stable than tinkering with individual pages.

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1989
  • MegaZine3 Developer
    • MegaZine3
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #4 on: November 23, 2009, 02:26:38 pm »
The adding and removal functions will be available via JavaScript in the next version. You will be able to do something like this:

Code: (javascript)
  1. MegaZine.removePage(10); // removes the 6th physical page from the book
  2.                         // (counting starts with 0 for page sides, so the 10 is the even part of the 6th
  3.                         // physical page.
  4. // adds a page with the given xml definition before the new 10th page (6th phyiscal), thus effectively replacing the old one
  5. MegaZine.addPageAt("<page><img src=\"data/someimg.jpg\"></page><page><vid src=\"data/somevid.f4v\"></page>", 10);

Removal should work, I didn't test if this properly cleans up all the time, though (i.e. if there are possible memory leaks), but it should be enough to start developing for now, until I find the time to take a closer look.
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.

kongo09

  • Jr. Member
  • **
  • Posts: 43
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #5 on: November 23, 2009, 02:33:12 pm »
Great! Many thanks!

Is there a similar call that reloads the whole book (in case the .mz3 file has changed)?

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1989
  • MegaZine3 Developer
    • MegaZine3
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #6 on: November 23, 2009, 03:18:56 pm »
Sorry, but nope, because there are some settings that would require a major reinitialization (e.g. page sizes), in which case it's be easier to just create a new MegaZine instance (might be I'll put that in the engine one day, i.e. the possibility to completely reload, but not soonish).
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.

kongo09

  • Jr. Member
  • **
  • Posts: 43
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #7 on: November 24, 2009, 11:41:23 am »
I see. I thought it would be as simple as removing all pages followed by adding the new pages as described above.

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1989
  • MegaZine3 Developer
    • MegaZine3
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #8 on: November 24, 2009, 07:06:11 pm »
Well if it's just a change of content, then yes. But as soon as a change of settings comes into play this gets kinda ugly, because all the plugins and some classes would have to be reinitialized and so on.
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.

kongo09

  • Jr. Member
  • **
  • Posts: 43
Re: Is it possible to replace individual pages once the book is loaded?
« Reply #9 on: November 25, 2009, 12:21:33 am »
Ah, sorry, I was primarily thinking of a change of content.