Author Topic: Actionscript help  (Read 2668 times)

ramjet

  • Newbie
  • *
  • Posts: 23
Actionscript help
« on: July 05, 2009, 12:26:12 pm »
Hi all,
I have a single frame swf(container.swf), which loads a 60 frame swf (inside.swf).

inside.swf has a button link with this code on frame 1.

Code: [Select]
on (release)
{
    gotoAndStop(56);
}

this sends inside.swf to frame 56.
I cannot touch this code, or any code written in inside.swf.

What i want to try and do is intercept this using code placed in container.swf, so that when the link is clicked it sets a variable called thePageNum (in container.swf) to 56 (the gotoAndStop framenumber).
I would also like to CANCEL the gotoAndStop action...so the on(release) does nothing.
Maybe container.swf has to listen for any gotoAndStops in inside.swf

Is this possible at all?
cheers, murray.
« Last Edit: July 06, 2009, 03:34:41 am by ramjet »

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Actionscript help
« Reply #1 on: July 06, 2009, 07:12:21 pm »
Hi,

related to the pdf thing, I guess? ;)

Didn't follow that trail until now, but had a look and it doesn't seem as if there's any event for frame changes.
There's a description of how to watch for frame changes nonetheless, it's a bit of a hack, though - just checks
on every renderpass if the frame has changed... anyway, link: http://www.adobe.com/devnet/flash/articles/timelinewatcher.html

With that you might check if the frame has changed, and if so do your thing, then force the inner swf to go back to the previous
frame.

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.

ramjet

  • Newbie
  • *
  • Posts: 23
Re: Actionscript help
« Reply #2 on: July 07, 2009, 02:51:56 am »
yip... the pdf thing.   ;D
Thanks for the link and idea Florian. I'll look into it.

I've got as far as pulling a sixty page pdf into megazine (in the form of a swf) and having the pages work, all is good except that the initial navigation links built into the loaded swf (by pdf2swf) are self-referential.
http://vidweb.org/megazine loads sixty 1 page swfs.
http://vidweb.org/megazine2 loads one 60 page swf.

I think I'm actually in favour of the sixty 1-page swfs because of loading time, as the size of a single page is considerably less than the size of a complete book....and this allows seeking forward through megazines controls.
So really I need to somehow listen from my container for the on(release) gotoAndStop event rather than a frame change, as there will be no frames.
(The gotoAndStop event actually does nothing in the first example, so i wouldn't need to "correct" it... just hear the frame number and get it into thePageNum variable in container.swf).

I love Megazine, and realise its a lot more versatile than what i'm trying to do with it,  but i think seamless integration with pdfs would be a great thing for it to be able to do.
The whole methodology is there already, apart from pdf document link integration.
Thanks for all your help.
murray.

edit: a related question.... is megazine coded to send events to swfaddress, or does swfaddress just listen? I'm wondering if this is a solution somehow (as if I use onepage swfs all that has to happen is Megazine needs to go to page 56)
« Last Edit: July 07, 2009, 03:33:21 am by ramjet »

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Actionscript help
« Reply #3 on: July 07, 2009, 11:35:02 am »
Yeah, I, too, think it'd be great if it were simpler to have better PDF integration. If you get it to work I'd definitely be interested in the details! :)

SWFAddress: everything related to that is implemented in the Main class. There's one listener for page change events attached to the book, calling the proper function in SWFAddress to update it, and one listener attached to SWFAddress, calling the gotoPage in the MegaZine instance accordingly.
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.

ramjet

  • Newbie
  • *
  • Posts: 23
Re: Actionscript help
« Reply #4 on: July 09, 2009, 02:23:09 pm »
I can get the swfs link to do this....

Code: [Select]
        public function clickbutton289(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame22"));
            return;
        }// end function

instead of the gotoAndStop.

Does this open up any possibility of being interpreted by Megazine to sending Megazine to page 22?
(Again sorry, I don't understand actionscript..or Megazine)

ramjet

  • Newbie
  • *
  • Posts: 23
Re: Actionscript help
« Reply #5 on: July 10, 2009, 04:33:43 am »
A post I found:

Quote
I generate a swf from pdf with
    pdf2swf -P=%s -p %d-%d -s ignoredraworder -s poly2bitmap -s
jpegquality=90 -s jpegdpi=120  -s internallinkfunction=dolink -s insertstop
-s zoom=75 %s %s ....
 
instead of gotoFrame there should a call of dolink with page as param ,
right ?
 
but how can I put this dolink funktion in this flash ?
I try to define a funtion on the root flash not on a frame, how to do that
with swfc or flash .
somethink like this
 
.flash filename="dolink.swf"
 function dolink(pageno) {
 getURL("page://"+pageno);
 )
.end

does'nt work
 
After that I have to use swfcombine ?
 



Convert the file using

    pdf2swf -s internallinkfunction=_parent.dolink document.pdf -o
document.swf

and then try this:

    .flash filename="dolink.swf"
       .swf document "document.swf"
       .action:
            function dolink(pageno) {
               getURL("http://www.test"+pageno+".com";, "parent");
            }
       .end
       .put document
    .end

I achieved this change in the button action by modifying pdf2megazine, and replacing the parameter zoom=100 with the parameter internallinkfunction=parent.dolink (i had to replace zoom, rather than just add internallinkfunction, otherwise the script wouldn't recognise the output file).
Unfortunately I don't know what to do with this changed code.


In fact heres the full code within x1.swf, which is one frame, and contains one page of the 60 page pdf.
This page is essentially only links to the rest of the pdf, now in function form rather than goto form.

Code: [Select]
package rfx
{
    import flash.display.*;
    import flash.events.*;
    import flash.system.*;

    dynamic public class MainTimeline extends MovieClip
    {
        public var button30:SimpleButton;
        public var button33:SimpleButton;
        public var button36:SimpleButton;
        public var button39:SimpleButton;
        public var button42:SimpleButton;
        public var button45:SimpleButton;
        public var button48:SimpleButton;
        public var button51:SimpleButton;
        public var button54:SimpleButton;
        public var button57:SimpleButton;
        public var button60:SimpleButton;
        public var button63:SimpleButton;
        public var button66:SimpleButton;
        public var button69:SimpleButton;
        public var button72:SimpleButton;
        public var button75:SimpleButton;
        public var button78:SimpleButton;
        public var button81:SimpleButton;
        public var button84:SimpleButton;
        public var button87:SimpleButton;
        public var button90:SimpleButton;
        public var button93:SimpleButton;
        public var button96:SimpleButton;
        public var button99:SimpleButton;
        public var button102:SimpleButton;
        public var button105:SimpleButton;
        public var button108:SimpleButton;
        public var button111:SimpleButton;
        public var button114:SimpleButton;
        public var button117:SimpleButton;
        public var button120:SimpleButton;
        public var button123:SimpleButton;
        public var button126:SimpleButton;
        public var button129:SimpleButton;
        public var button132:SimpleButton;
        public var button135:SimpleButton;
        public var button138:SimpleButton;
        public var button141:SimpleButton;
        public var button144:SimpleButton;
        public var button147:SimpleButton;
        public var button150:SimpleButton;
        public var button153:SimpleButton;
        public var button156:SimpleButton;
        public var button159:SimpleButton;

        public function MainTimeline()
        {
            Security.allowDomain("*");
            addFrameScript(0, frame0);
            return;
        }// end function

        function frame0()
        {
            stop();
            button30.addEventListener(MouseEvent.CLICK, clickbutton30);
            button33.addEventListener(MouseEvent.CLICK, clickbutton33);
            button36.addEventListener(MouseEvent.CLICK, clickbutton36);
            button39.addEventListener(MouseEvent.CLICK, clickbutton39);
            button42.addEventListener(MouseEvent.CLICK, clickbutton42);
            button45.addEventListener(MouseEvent.CLICK, clickbutton45);
            button48.addEventListener(MouseEvent.CLICK, clickbutton48);
            button51.addEventListener(MouseEvent.CLICK, clickbutton51);
            button54.addEventListener(MouseEvent.CLICK, clickbutton54);
            button57.addEventListener(MouseEvent.CLICK, clickbutton57);
            button60.addEventListener(MouseEvent.CLICK, clickbutton60);
            button63.addEventListener(MouseEvent.CLICK, clickbutton63);
            button66.addEventListener(MouseEvent.CLICK, clickbutton66);
            button69.addEventListener(MouseEvent.CLICK, clickbutton69);
            button72.addEventListener(MouseEvent.CLICK, clickbutton72);
            button75.addEventListener(MouseEvent.CLICK, clickbutton75);
            button78.addEventListener(MouseEvent.CLICK, clickbutton78);
            button81.addEventListener(MouseEvent.CLICK, clickbutton81);
            button84.addEventListener(MouseEvent.CLICK, clickbutton84);
            button87.addEventListener(MouseEvent.CLICK, clickbutton87);
            button90.addEventListener(MouseEvent.CLICK, clickbutton90);
            button93.addEventListener(MouseEvent.CLICK, clickbutton93);
            button96.addEventListener(MouseEvent.CLICK, clickbutton96);
            button99.addEventListener(MouseEvent.CLICK, clickbutton99);
            button102.addEventListener(MouseEvent.CLICK, clickbutton102);
            button105.addEventListener(MouseEvent.CLICK, clickbutton105);
            button108.addEventListener(MouseEvent.CLICK, clickbutton108);
            button111.addEventListener(MouseEvent.CLICK, clickbutton111);
            button114.addEventListener(MouseEvent.CLICK, clickbutton114);
            button117.addEventListener(MouseEvent.CLICK, clickbutton117);
            button120.addEventListener(MouseEvent.CLICK, clickbutton120);
            button123.addEventListener(MouseEvent.CLICK, clickbutton123);
            button126.addEventListener(MouseEvent.CLICK, clickbutton126);
            button129.addEventListener(MouseEvent.CLICK, clickbutton129);
            button132.addEventListener(MouseEvent.CLICK, clickbutton132);
            button135.addEventListener(MouseEvent.CLICK, clickbutton135);
            button138.addEventListener(MouseEvent.CLICK, clickbutton138);
            button141.addEventListener(MouseEvent.CLICK, clickbutton141);
            button144.addEventListener(MouseEvent.CLICK, clickbutton144);
            button147.addEventListener(MouseEvent.CLICK, clickbutton147);
            button150.addEventListener(MouseEvent.CLICK, clickbutton150);
            button153.addEventListener(MouseEvent.CLICK, clickbutton153);
            button156.addEventListener(MouseEvent.CLICK, clickbutton156);
            button159.addEventListener(MouseEvent.CLICK, clickbutton159);
            return;
        }// end function

        public function clickbutton30(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame17"));
            return;
        }// end function

        public function clickbutton33(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame16"));
            return;
        }// end function

        public function clickbutton36(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame16"));
            return;
        }// end function

        public function clickbutton39(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame16"));
            return;
        }// end function

        public function clickbutton42(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame16"));
            return;
        }// end function

        public function clickbutton45(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame15"));
            return;
        }// end function

        public function clickbutton48(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame15"));
            return;
        }// end function

        public function clickbutton51(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame15"));
            return;
        }// end function

        public function clickbutton54(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame14"));
            return;
        }// end function

        public function clickbutton57(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame13"));
            return;
        }// end function

        public function clickbutton60(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame13"));
            return;
        }// end function

        public function clickbutton63(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame13"));
            return;
        }// end function

        public function clickbutton66(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame12"));
            return;
        }// end function

        public function clickbutton69(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame12"));
            return;
        }// end function

        public function clickbutton72(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame11"));
            return;
        }// end function

        public function clickbutton75(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame11"));
            return;
        }// end function

        public function clickbutton78(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame11"));
            return;
        }// end function

        public function clickbutton81(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame11"));
            return;
        }// end function

        public function clickbutton84(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame10"));
            return;
        }// end function

        public function clickbutton87(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame10"));
            return;
        }// end function

        public function clickbutton90(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame10"));
            return;
        }// end function

        public function clickbutton93(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame10"));
            return;
        }// end function

        public function clickbutton96(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame10"));
            return;
        }// end function

        public function clickbutton99(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame9"));
            return;
        }// end function

        public function clickbutton102(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame8"));
            return;
        }// end function

        public function clickbutton105(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame8"));
            return;
        }// end function

        public function clickbutton108(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame7"));
            return;
        }// end function

        public function clickbutton111(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame7"));
            return;
        }// end function

        public function clickbutton114(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame7"));
            return;
        }// end function

        public function clickbutton117(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame7"));
            return;
        }// end function

        public function clickbutton120(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame7"));
            return;
        }// end function

        public function clickbutton123(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame6"));
            return;
        }// end function

        public function clickbutton126(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame6"));
            return;
        }// end function

        public function clickbutton129(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame5"));
            return;
        }// end function

        public function clickbutton132(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame5"));
            return;
        }// end function

        public function clickbutton135(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame5"));
            return;
        }// end function

        public function clickbutton138(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame5"));
            return;
        }// end function

        public function clickbutton141(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame5"));
            return;
        }// end function

        public function clickbutton144(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame5"));
            return;
        }// end function

        public function clickbutton147(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame4"));
            return;
        }// end function

        public function clickbutton150(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "frame4"));
            return;
        }// end function

        public function clickbutton153(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "http://www.nss.pl/"));
            return;
        }// end function

        public function clickbutton156(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "http://www.nss.pl/"));
            return;
        }// end function

        public function clickbutton159(param1:MouseEvent)
        {
            this.dispatchEvent(new TextEvent("link", true, true, "http://www.nss.pl/"));
            return;
        }// end function

    }
}

Ideally I would NOT want to use any container to load the 60 swfs...just have Megazine be able to deal with these button clicks.
Is this on the right track do you think??
« Last Edit: July 10, 2009, 04:49:53 am by ramjet »

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Actionscript help
« Reply #6 on: July 12, 2009, 02:09:52 pm »
That sounds neat. What you could probably do now is add an event listener to that generated code (listening to TextEvents) and act upon that. I'd imagine something along those lines might work:

Code: (actionscript3)
  1. var l:Loader = new Loader();
  2.  
  3. // use l to load your x1.swf
  4.  
  5. // called when loading completes
  6. function handleSwfLoaded(e:Event):void {
  7.  var swfInner:DisplayObject = l.getChildAt(0); // get you loaded swf out of the loader
  8.  swfInner.addEventListener(TextEvent.LINK, handleLink);
  9. }
  10.  
  11. // called when one of those this.dispatchEvent(new TextEvent("link", true, true, "frameXX")); is run
  12. function handleLink(e:TextEvent):void {
  13.  var lnk:String = e.text;
  14.  if (lnk.indexOf("frame") == 0) {
  15.    // Internal link, remove the frame part
  16.    lnk = lnk.substring(5);
  17.    mz.gotoPage(int(lnk));
  18.  } else {
  19.    // URL
  20.    navigateToURL(new URLRequest(lnk));
  21.  }
  22. }

Just guessing, though...
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.

ramjet

  • Newbie
  • *
  • Posts: 23
Re: Actionscript help
« Reply #7 on: July 13, 2009, 12:18:58 pm »
Thanks Florian  :)
I have to shift house, but i'll have a look in a week or so.
I take it this means I still need to load my 60 swfs into a container swf? (otherwise i'd have nowhere to put the code?)

Is there any way Megazine could have something in the xml (listenforInternallinkfunction=true) which alongside a specific command in pdf2megazine (internallinkfunction=megazineHear) could dispense with any container.swf and set up the listener within Megazine itself?
Anyway food for thought. Cheers, murray.

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Actionscript help
« Reply #8 on: July 18, 2009, 10:02:58 pm »
Not sure how the swfs pdf2swf generates work internally, will have to have a closer look at the documentation for that... when I find the time ;)
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.

wsherliker

  • Newbie
  • *
  • Posts: 1
Re: Actionscript help
« Reply #9 on: June 17, 2010, 11:16:47 am »
Just one additional note on this - the links plugin now handles these links. However I found that the regular expression used in the links plugin to match internal links was designed for those with frameXX_{32 char key}. This was not always the case as sometimes the key is missing i.e. they are just frameXX so I altered the regular expression to /frame(\d+)/i. I suspect this will not cause any false positive matches and it works on more SWFs for internal linking.

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: Actionscript help
« Reply #10 on: June 19, 2010, 02:03:33 pm »
Good to know, will adjust the plugin accordingly.

Just to clarify, this and the previous post refer to version 2.x.
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.