Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 2634

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>SWFAction</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Ming functions for Flash"
HREF="ref.ming.html"><LINK
REL="PREVIOUS"
TITLE="ming_useswfversion"
HREF="function.ming-useswfversion.html"><LINK
REL="NEXT"
TITLE="SWFBitmap->getHeight"
HREF="function.swfbitmap.getheight.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.ming-useswfversion.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.swfbitmap.getheight.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.swfaction"
></A
>SWFAction</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN52768"
></A
><P
>    (PHP 4 &#62;= 4.0.5)</P
>SWFAction&nbsp;--&nbsp;Creates a new Action.</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN52771"
></A
><H2
>Description</H2
>new <B
CLASS="methodname"
>swfaction</B
> ( string script)<BR
></BR
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Warning</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>This function is
<SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>EXPERIMENTAL</I
></SPAN
>. The behaviour of this function, the
name of this function, and anything else documented about this
function may change without notice in a future release of PHP. 
Use this function at your own risk.</P
></TD
></TR
></TABLE
></DIV
><P
>&#13;     <B
CLASS="function"
>swfaction()</B
> creates a new Action, and
     compiles the given script into an SWFAction object. 
    </P
><P
>&#13;     The script syntax is based on the C language, but with a lot taken out- the SWF
     bytecode machine is just too simpleminded to do a lot of things we might like. 
     For instance, we can't implement function calls without a tremendous 
     amount of hackery because the jump bytecode has a hardcoded offset 
     value. No pushing your calling address to the stack and returning- 
     every function would have to know exactly where to return to. 
    </P
><P
>&#13;     So what's left? The compiler recognises the following tokens: 
     <P
></P
><UL
><LI
><P
>&#13;        break
       </P
></LI
><LI
><P
>&#13;        for
       </P
></LI
><LI
><P
>&#13;        continue
       </P
></LI
><LI
><P
>&#13;        if
       </P
></LI
><LI
><P
>&#13;        else
       </P
></LI
><LI
><P
>&#13;        do
       </P
></LI
><LI
><P
>&#13;        while
       </P
></LI
></UL
>
    </P
><P
>&#13;     There is no typed data; all values in the SWF action machine are stored as strings. 
     The following functions can be used in expressions: 
     <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
>time()</DT
><DD
><P
>&#13;         Returns the number of milliseconds (?) elapsed since the movie started. 
        </P
></DD
><DT
>random(seed)</DT
><DD
><P
>&#13;         Returns a pseudo-random number in the range 0-seed.
        </P
></DD
><DT
>length(expr)</DT
><DD
><P
>&#13;         Returns the length of the given expression. 
        </P
></DD
><DT
>int(number)</DT
><DD
><P
>&#13;         Returns the given number rounded down to the nearest integer. 
        </P
></DD
><DT
>concat(expr, expr)</DT
><DD
><P
>&#13;         Returns the concatenation of the given expressions. 
        </P
></DD
><DT
>ord(expr)</DT
><DD
><P
>&#13;         Returns the ASCII code for the given character 
        </P
></DD
><DT
>chr(num)</DT
><DD
><P
>&#13;         Returns the character for the given ASCII code 
        </P
></DD
><DT
>substr(string, location, length)</DT
><DD
><P
>&#13;         Returns the substring of length length at location location of 
         the given string string.
        </P
></DD
></DL
></DIV
>
    </P
><P
>&#13;     Additionally, the following commands may be used: 
     <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
>duplicateClip(clip, name, depth)</DT
><DD
><P
>&#13;         Duplicate the named movie clip (aka sprite). The new movie clip has name name 
         and is at depth depth. 
        </P
></DD
><DT
>removeClip(expr)</DT
><DD
><P
>&#13;         Removes the named movie clip. 
        </P
></DD
><DT
>trace(expr)</DT
><DD
><P
>&#13;         Write the given expression to the trace log. Doubtful that the browser
         plugin does anything with this. 
        </P
></DD
><DT
>startDrag(target, lock, [left, top, right, bottom])</DT
><DD
><P
>&#13;         Start dragging the movie clip target. The lock argument indicates whether 
         to lock the mouse (?)- use 0 (<TT
CLASS="constant"
><B
>FALSE</B
></TT
>) or 1 (<TT
CLASS="constant"
><B
>TRUE</B
></TT
>). Optional parameters 
         define a bounding area for the dragging.  
        </P
></DD
><DT
>stopDrag()</DT
><DD
><P
>&#13;         Stop dragging my heart around. And this movie clip, too.  
        </P
></DD
><DT
>callFrame(expr)</DT
><DD
><P
>&#13;         Call the named frame as a function.  
        </P
></DD
><DT
>getURL(url, target, [method])</DT
><DD
><P
>&#13;         Load the given URL into the named target. The target argument
         corresponds to HTML document targets (such as "_top" or "_blank").
         The optional method argument can be POST or GET if you want to submit 
         variables back to the server.  
        </P
></DD
><DT
>loadMovie(url, target)</DT
><DD
><P
>&#13;         Load the given URL into the named target. The target argument can be a 
         frame name (I think), or one of the magical values "_level0" (replaces 
         current movie) or "_level1" (loads new movie on top of current movie). 
        </P
></DD
><DT
>nextFrame()</DT
><DD
><P
>&#13;         Go to the next frame.  
        </P
></DD
><DT
>prevFrame()</DT
><DD
><P
>&#13;         Go to the last (or, rather, previous) frame.  
        </P
></DD
><DT
>play()</DT
><DD
><P
>&#13;         Start playing the movie.  
        </P
></DD
><DT
>stop()</DT
><DD
><P
>&#13;         Stop playing the movie.  
        </P
></DD
><DT
>toggleQuality()</DT
><DD
><P
>&#13;         Toggle between high and low quality.  
        </P
></DD
><DT
>stopSounds()</DT
><DD
><P
>&#13;         Stop playing all sounds.  
        </P
></DD
><DT
>gotoFrame(num)</DT
><DD
><P
>&#13;         Go to frame number num. Frame numbers start at 0.  
        </P
></DD
><DT
>gotoFrame(name)</DT
><DD
><P
>&#13;         Go to the frame named name. Which does a lot of good, since I 
         haven't added frame labels yet.  
        </P
></DD
><DT
>setTarget(expr)</DT
><DD
><P
>&#13;         Sets the context for action. Or so they say- I really have no 
         idea what this does. 
        </P
></DD
></DL
></DIV
>
     And there's one weird extra thing. The expression frameLoaded(num) can be used
     in if statements and while loops to check if the given frame number has been
     loaded yet. Well, it's supposed to, anyway, but I've never tested it and I
     seriously doubt it actually works. You can just use /:framesLoaded instead. 
    </P
><P
>&#13;      Movie clips (all together now- aka sprites) have properties. You can 
      read all of them (or can you?), you can set some of them, and here 
      they are: 
      <P
></P
><UL
><LI
><P
>&#13;         x
        </P
></LI
><LI
><P
>&#13;         y 
        </P
></LI
><LI
><P
>&#13;         xScale 
        </P
></LI
><LI
><P
>&#13;         yScale 
        </P
></LI
><LI
><P
>&#13;         currentFrame - (read-only) 
        </P
></LI
><LI
><P
>&#13;         totalFrames - (read-only) 
        </P
></LI
><LI
><P
>&#13;         alpha - transparency level 
        </P
></LI
><LI
><P
>&#13;         visible - 1=on, 0=off (?) 
        </P
></LI
><LI
><P
>&#13;         width - (read-only) 
        </P
></LI
><LI
><P
>&#13;         height - (read-only) 
        </P
></LI
><LI
><P
>&#13;         rotation 
        </P
></LI
><LI
><P
>&#13;         target - (read-only) (???) 
        </P
></LI
><LI
><P
>&#13;         framesLoaded - (read-only) 
        </P
></LI
><LI
><P
>&#13;         name 
        </P
></LI
><LI
><P
>&#13;         dropTarget - (read-only) (???) 
        </P
></LI
><LI
><P
>&#13;         url - (read-only) (???) 
        </P
></LI
><LI
><P
>&#13;         highQuality - 1=high, 0=low (?) 
        </P
></LI
><LI
><P
>&#13;         focusRect - (???) 
        </P
></LI
><LI
><P
>&#13;         soundBufTime - (???) 
        </P
></LI
></UL
>
      So, setting a sprite's x position is as simple as <TT
CLASS="literal"
>/box.x = 100;</TT
>. 
      Why the slash in front of the box, though? That's how flash keeps
      track of the sprites in the movie, just like a unix filesystem- 
      here it shows that box is at the top level. If the sprite named 
      box had another sprite named biff inside of it, you'd set its x 
      position with /box/biff.x = 100;. At least, I think so; correct 
      me if I'm wrong here. 
    </P
><P
>&#13;     This simple example will move the red square across the window.
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN52949"
></A
><P
><B
>Example 1. <B
CLASS="function"
>swfaction()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
 $s = new SWFShape();
  $f = $s-&#62;addFill(0xff, 0, 0);
  $s-&#62;setRightFill($f);

  $s-&#62;movePenTo(-500,-500);
  $s-&#62;drawLineTo(500,-500);
  $s-&#62;drawLineTo(500,500);
  $s-&#62;drawLineTo(-500,500);
  $s-&#62;drawLineTo(-500,-500);

  $p = new SWFSprite();
  $i = $p-&#62;add($s);
  $i-&#62;setDepth(1);
  $p-&#62;nextFrame();

  for($n=0; $n&#60;5; ++$n)
  {
    $i-&#62;rotate(-15);
    $p-&#62;nextFrame();
  }

  $m = new SWFMovie();
  $m-&#62;setBackground(0xff, 0xff, 0xff);
  $m-&#62;setDimension(6000,4000);

  $i = $m-&#62;add($p);
  $i-&#62;setDepth(1);
  $i-&#62;moveTo(-500,2000);
  $i-&#62;setName("box");

  $m-&#62;add(new SWFAction("/box.x += 3;"));
  $m-&#62;nextFrame();
  $m-&#62;add(new SWFAction("gotoFrame(0); play();"));
  $m-&#62;nextFrame();

  header('Content-type: application/x-shockwave-flash');
  $m-&#62;output();
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     This simple example tracks down your mouse on the screen.
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN52954"
></A
><P
><B
>Example 2. <B
CLASS="function"
>swfaction()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

  $m = new SWFMovie();
  $m-&#62;setRate(36.0);
  $m-&#62;setDimension(1200, 800);
  $m-&#62;setBackground(0, 0, 0);

  /* mouse tracking sprite - empty, but follows mouse so we can
     get its x and y coordinates */

  $i = $m-&#62;add(new SWFSprite());
  $i-&#62;setName('mouse');

  $m-&#62;add(new SWFAction("
    startDrag('/mouse', 1); /* '1' means lock sprite to the mouse */
  "));

  /* might as well turn off antialiasing, since these are just squares. */

  $m-&#62;add(new SWFAction("
    this.quality = 0;
  "));

  /* morphing box */
  $r = new SWFMorph();
  $s = $r-&#62;getShape1();

  /* Note this is backwards from normal shapes.  No idea why. */
  $s-&#62;setLeftFill($s-&#62;addFill(0xff, 0xff, 0xff));
  $s-&#62;movePenTo(-40, -40);
  $s-&#62;drawLine(80, 0);
  $s-&#62;drawLine(0, 80);
  $s-&#62;drawLine(-80, 0);
  $s-&#62;drawLine(0, -80);

  $s = $r-&#62;getShape2();

  $s-&#62;setLeftFill($s-&#62;addFill(0x00, 0x00, 0x00));
  $s-&#62;movePenTo(-1, -1);
  $s-&#62;drawLine(2, 0);
  $s-&#62;drawLine(0, 2);
  $s-&#62;drawLine(-2, 0);
  $s-&#62;drawLine(0, -2);

  /* sprite container for morphing box -
     this is just a timeline w/ the box morphing */

  $box = new SWFSprite();
  $box-&#62;add(new SWFAction("
    stop();
  "));
  $i = $box-&#62;add($r);

  for($n=0; $n&#60;=20; ++$n)
  {
    $i-&#62;setRatio($n/20);
    $box-&#62;nextFrame();
  }

  /* this container sprite allows us to use the same action code many times */

  $cell = new SWFSprite();
  $i = $cell-&#62;add($box);
  $i-&#62;setName('box');

  $cell-&#62;add(new SWFAction("

    setTarget('box');

    /* ...x means the x coordinate of the parent, i.e. (..).x */
    dx = (/mouse.x + random(6)-3 - ...x)/5;
    dy = (/mouse.y + random(6)-3 - ...y)/5;
    gotoFrame(int(dx*dx + dy*dy));

  "));

  $cell-&#62;nextFrame();
  $cell-&#62;add(new SWFAction("

    gotoFrame(0);
    play();

  "));

  $cell-&#62;nextFrame();

  /* finally, add a bunch of the cells to the movie */

  for($x=0; $x&#60;12; ++$x)
  {
    for($y=0; $y&#60;8; ++$y)
    {
      $i = $m-&#62;add($cell);
      $i-&#62;moveTo(100*$x+50, 100*$y+50);
    }
  }

  $m-&#62;nextFrame();

  $m-&#62;add(new SWFAction("

    gotoFrame(1);
    play();

  "));

  header('Content-type: application/x-shockwave-flash');
  $m-&#62;output();
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     Same as above, but with nice colored balls...
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN52959"
></A
><P
><B
>Example 3. <B
CLASS="function"
>swfaction()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

  $m = new SWFMovie();
  $m-&#62;setDimension(11000, 8000);
  $m-&#62;setBackground(0x00, 0x00, 0x00);

  $m-&#62;add(new SWFAction("

this.quality = 0;
/frames.visible = 0;
startDrag('/mouse', 1);

  "));

  // mouse tracking sprite
  $t = new SWFSprite();
  $i = $m-&#62;add($t);
  $i-&#62;setName('mouse');

  $g = new SWFGradient();
  $g-&#62;addEntry(0, 0xff, 0xff, 0xff, 0xff);
  $g-&#62;addEntry(0.1, 0xff, 0xff, 0xff, 0xff);
  $g-&#62;addEntry(0.5, 0xff, 0xff, 0xff, 0x5f);
  $g-&#62;addEntry(1.0, 0xff, 0xff, 0xff, 0);

  // gradient shape thing
  $s = new SWFShape();
  $f = $s-&#62;addFill($g, SWFFILL_RADIAL_GRADIENT);
  $f-&#62;scaleTo(0.03);
  $s-&#62;setRightFill($f);
  $s-&#62;movePenTo(-600, -600);
  $s-&#62;drawLine(1200, 0);
  $s-&#62;drawLine(0, 1200);
  $s-&#62;drawLine(-1200, 0);
  $s-&#62;drawLine(0, -1200);

  // need to make this a sprite so we can multColor it
  $p = new SWFSprite();
  $p-&#62;add($s);
  $p-&#62;nextFrame();

  // put the shape in here, each frame a different color
  $q = new SWFSprite();
  $q-&#62;add(new SWFAction("gotoFrame(random(7)+1); stop();"));
  $i = $q-&#62;add($p);

  $i-&#62;multColor(1.0, 1.0, 1.0);
  $q-&#62;nextFrame();
  $i-&#62;multColor(1.0, 0.5, 0.5);
  $q-&#62;nextFrame();
  $i-&#62;multColor(1.0, 0.75, 0.5);
  $q-&#62;nextFrame();
  $i-&#62;multColor(1.0, 1.0, 0.5);
  $q-&#62;nextFrame();
  $i-&#62;multColor(0.5, 1.0, 0.5);
  $q-&#62;nextFrame();
  $i-&#62;multColor(0.5, 0.5, 1.0);
  $q-&#62;nextFrame();
  $i-&#62;multColor(1.0, 0.5, 1.0);
  $q-&#62;nextFrame();

  // finally, this one contains the action code
  $p = new SWFSprite();
  $i = $p-&#62;add($q);
  $i-&#62;setName('frames');
  $p-&#62;add(new SWFAction("

dx = (/:mousex-/:lastx)/3 + random(10)-5;
dy = (/:mousey-/:lasty)/3;
x = /:mousex;
y = /:mousey;
alpha = 100;

  "));
  $p-&#62;nextFrame();

  $p-&#62;add(new SWFAction("

this.x = x;
this.y = y;
this.alpha = alpha;
x += dx;
y += dy;
dy += 3;
alpha -= 8;

  "));
  $p-&#62;nextFrame();

  $p-&#62;add(new SWFAction("prevFrame(); play();"));
  $p-&#62;nextFrame();

  $i = $m-&#62;add($p);
  $i-&#62;setName('frames');
  $m-&#62;nextFrame();

  $m-&#62;add(new SWFAction("

lastx = mousex;
lasty = mousey;
mousex = /mouse.x;
mousey = /mouse.y;

++num;

if(num == 11)
  num = 1;

removeClip('char' &#38; num);
duplicateClip(/frames, 'char' &#38; num, num);

  "));

  $m-&#62;nextFrame();
  $m-&#62;add(new SWFAction("prevFrame(); play();"));

  header('Content-type: application/x-shockwave-flash');
  $m-&#62;output();
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     This simple example will handles keyboard actions.
     (You'll probably have to click in the window to give it focus.
     And you'll probably have to leave your mouse in the frame, too.
     If you know how to give buttons focus programatically, feel free
     to share, won't you?) 
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN52964"
></A
><P
><B
>Example 4. <B
CLASS="function"
>swfaction()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

  /* sprite has one letter per frame */

  $p = new SWFSprite();
  $p-&#62;add(new SWFAction("stop();"));

  $chars = "abcdefghijklmnopqrstuvwxyz".
       "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
           "1234567890!@#$%^&#38;/*()_+-=/[]{}|;:,.&#60;&#62;?`~";

  $f = new SWFFont("_sans");

  for($n=0; $nremove($i);
    $t = new SWFTextField();
    $t-&#62;setFont($f);
    $t-&#62;setHeight(240);
    $t-&#62;setBounds(600,240);
    $t-&#62;align(SWFTEXTFIELD_ALIGN_CENTER);
    $t-&#62;addString($c);
    $i = $p-&#62;add($t);
    $p-&#62;labelFrame($c);
    $p-&#62;nextFrame();
  }

  /* hit region for button - the entire frame */

  $s = new SWFShape();
  $s-&#62;setFillStyle0($s-&#62;addSolidFill(0, 0, 0, 0));
  $s-&#62;drawLine(600, 0);
  $s-&#62;drawLine(0, 400);
  $s-&#62;drawLine(-600, 0);
  $s-&#62;drawLine(0, -400);

  /* button checks for pressed key, sends sprite to the right frame */

  $b = new SWFButton();
  $b-&#62;addShape($s, SWFBUTTON_HIT);

  for($n=0; $naddAction(new SWFAction("

setTarget('/char');
gotoFrame('$c');

    "), SWFBUTTON_KEYPRESS($c));
  }

  $m = new SWFMovie();
  $m-&#62;setDimension(600,400);
  $i = $m-&#62;add($p);
  $i-&#62;setName('char');
  $i-&#62;moveTo(0,80);

  $m-&#62;add($b);

  header('Content-type: application/x-shockwave-flash');
  $m-&#62;output();

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.ming-useswfversion.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.swfbitmap.getheight.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>ming_useswfversion</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.ming.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>SWFBitmap-&#62;getHeight</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>