1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- splitted from ./en/functions/ming.xml, last change in rev 1.24 -->
<refentry id="function.swfaction">
<refnamediv>
<refname>SWFAction</refname>
<refpurpose>Creates a new Action</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>SWFAction</type><methodname>swfaction</methodname>
<methodparam><type>string</type><parameter>script</parameter></methodparam>
</methodsynopsis>
&warn.experimental.func;
<para>
<function>swfaction</function> creates a new Action, and
compiles the given script into an SWFAction object.
</para>
<para>
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.
</para>
<para>
So what's left? The compiler recognises the following tokens:
<itemizedlist>
<listitem>
<simpara>
break
</simpara>
</listitem>
<listitem>
<simpara>
for
</simpara>
</listitem>
<listitem>
<simpara>
continue
</simpara>
</listitem>
<listitem>
<simpara>
if
</simpara>
</listitem>
<listitem>
<simpara>
else
</simpara>
</listitem>
<listitem>
<simpara>
do
</simpara>
</listitem>
<listitem>
<simpara>
while
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
There is no typed data; all values in the SWF action machine are stored as strings.
The following functions can be used in expressions:
<variablelist>
<varlistentry>
<term>time()</term>
<listitem>
<simpara>
Returns the number of milliseconds (?) elapsed since the movie started.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>random(seed)</term>
<listitem>
<simpara>
Returns a pseudo-random number in the range 0-seed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>length(expr)</term>
<listitem>
<simpara>
Returns the length of the given expression.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>int(number)</term>
<listitem>
<simpara>
Returns the given number rounded down to the nearest integer.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>concat(expr, expr)</term>
<listitem>
<simpara>
Returns the concatenation of the given expressions.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>ord(expr)</term>
<listitem>
<simpara>
Returns the ASCII code for the given character
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>chr(num)</term>
<listitem>
<simpara>
Returns the character for the given ASCII code
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>substr(string, location, length)</term>
<listitem>
<simpara>
Returns the substring of length <parameter>length</parameter> at location <parameter>location</parameter> of
the given string <parameter>string</parameter>.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
Additionally, the following commands may be used:
<variablelist>
<varlistentry>
<term>duplicateClip(clip, name, depth)</term>
<listitem>
<simpara>
Duplicate the named movie <parameter>clip</parameter> (aka sprite). The new movie clip has name <parameter>name</parameter>
and is at depth <parameter>depth</parameter>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>removeClip(expr)</term>
<listitem>
<simpara>
Removes the named movie clip.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>trace(expr)</term>
<listitem>
<simpara>
Write the given expression to the trace log. Doubtful that the browser
plugin does anything with this.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>startDrag(target, lock, [left, top, right, bottom])</term>
<listitem>
<simpara>
Start dragging the movie clip <parameter>target</parameter>. The <parameter>lock</parameter> argument indicates whether
to lock the mouse (?)- use 0 (&false;) or 1 (&true;). Optional parameters
define a bounding area for the dragging.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>stopDrag()</term>
<listitem>
<simpara>
Stop dragging my heart around. And this movie clip, too.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>callFrame(expr)</term>
<listitem>
<simpara>
Call the named frame as a function.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>getURL(url, target, [method])</term>
<listitem>
<simpara>
Load the given URL into the named target. The <parameter>target</parameter> argument
corresponds to HTML document targets (such as "_top" or "_blank").
The optional <parameter>method</parameter> argument can be POST or GET if you want to submit
variables back to the server.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>loadMovie(url, target)</term>
<listitem>
<simpara>
Load the given URL into the named target. The <parameter>target</parameter> 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).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>nextFrame()</term>
<listitem>
<simpara>
Go to the next frame.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>prevFrame()</term>
<listitem>
<simpara>
Go to the last (or, rather, previous) frame.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>play()</term>
<listitem>
<simpara>
Start playing the movie.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>stop()</term>
<listitem>
<simpara>
Stop playing the movie.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>toggleQuality()</term>
<listitem>
<simpara>
Toggle between high and low quality.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>stopSounds()</term>
<listitem>
<simpara>
Stop playing all sounds.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>gotoFrame(num)</term>
<listitem>
<simpara>
Go to frame number <parameter>num</parameter>. Frame numbers start at 0.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>gotoFrame(name)</term>
<listitem>
<simpara>
Go to the frame named <parameter>name</parameter>. Which does a lot of good, since I
haven't added frame labels yet.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>setTarget(expr)</term>
<listitem>
<simpara>
Sets the context for action. Or so they say- I really have no
idea what this does.
</simpara>
</listitem>
</varlistentry>
</variablelist>
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.
</para>
<para>
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:
<itemizedlist>
<listitem>
<simpara>
x
</simpara>
</listitem>
<listitem>
<simpara>
y
</simpara>
</listitem>
<listitem>
<simpara>
xScale
</simpara>
</listitem>
<listitem>
<simpara>
yScale
</simpara>
</listitem>
<listitem>
<simpara>
currentFrame - (read-only)
</simpara>
</listitem>
<listitem>
<simpara>
totalFrames - (read-only)
</simpara>
</listitem>
<listitem>
<simpara>
alpha - transparency level
</simpara>
</listitem>
<listitem>
<simpara>
visible - 1=on, 0=off (?)
</simpara>
</listitem>
<listitem>
<simpara>
width - (read-only)
</simpara>
</listitem>
<listitem>
<simpara>
height - (read-only)
</simpara>
</listitem>
<listitem>
<simpara>
rotation
</simpara>
</listitem>
<listitem>
<simpara>
target - (read-only) (???)
</simpara>
</listitem>
<listitem>
<simpara>
framesLoaded - (read-only)
</simpara>
</listitem>
<listitem>
<simpara>
name
</simpara>
</listitem>
<listitem>
<simpara>
dropTarget - (read-only) (???)
</simpara>
</listitem>
<listitem>
<simpara>
url - (read-only) (???)
</simpara>
</listitem>
<listitem>
<simpara>
highQuality - 1=high, 0=low (?)
</simpara>
</listitem>
<listitem>
<simpara>
focusRect - (???)
</simpara>
</listitem>
<listitem>
<simpara>
soundBufTime - (???)
</simpara>
</listitem>
</itemizedlist>
So, setting a sprite's x position is as simple as <literal>/box.x = 100;</literal>.
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.
</para>
<para>
This simple example will move the red square across the window.
<example>
<title><function>swfaction</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$s = new SWFShape();
$f = $s->addFill(0xff, 0, 0);
$s->setRightFill($f);
$s->movePenTo(-500, -500);
$s->drawLineTo(500, -500);
$s->drawLineTo(500, 500);
$s->drawLineTo(-500, 500);
$s->drawLineTo(-500, -500);
$p = new SWFSprite();
$i = $p->add($s);
$i->setDepth(1);
$p->nextFrame();
for ($n=0; $n<5; ++$n) {
$i->rotate(-15);
$p->nextFrame();
}
$m = new SWFMovie();
$m->setBackground(0xff, 0xff, 0xff);
$m->setDimension(6000, 4000);
$i = $m->add($p);
$i->setDepth(1);
$i->moveTo(-500,2000);
$i->setName("box");
$m->add(new SWFAction("/box.x += 3;"));
$m->nextFrame();
$m->add(new SWFAction("gotoFrame(0); play();"));
$m->nextFrame();
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
]]>
</programlisting>
</example>
</para>
<para>
This simple example tracks down your mouse on the screen.
<example>
<title><function>swfaction</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$m = new SWFMovie();
$m->setRate(36.0);
$m->setDimension(1200, 800);
$m->setBackground(0, 0, 0);
/* mouse tracking sprite - empty, but follows mouse so we can
get its x and y coordinates */
$i = $m->add(new SWFSprite());
$i->setName('mouse');
$m->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->add(new SWFAction("
this.quality = 0;
"));
/* morphing box */
$r = new SWFMorph();
$s = $r->getShape1();
/* Note this is backwards from normal shapes. No idea why. */
$s->setLeftFill($s->addFill(0xff, 0xff, 0xff));
$s->movePenTo(-40, -40);
$s->drawLine(80, 0);
$s->drawLine(0, 80);
$s->drawLine(-80, 0);
$s->drawLine(0, -80);
$s = $r->getShape2();
$s->setLeftFill($s->addFill(0x00, 0x00, 0x00));
$s->movePenTo(-1, -1);
$s->drawLine(2, 0);
$s->drawLine(0, 2);
$s->drawLine(-2, 0);
$s->drawLine(0, -2);
/* sprite container for morphing box -
this is just a timeline w/ the box morphing */
$box = new SWFSprite();
$box->add(new SWFAction("
stop();
"));
$i = $box->add($r);
for ($n=0; $n<=20; ++$n) {
$i->setRatio($n/20);
$box->nextFrame();
}
/* this container sprite allows us to use the same action code many times */
$cell = new SWFSprite();
$i = $cell->add($box);
$i->setName('box');
$cell->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->nextFrame();
$cell->add(new SWFAction("
gotoFrame(0);
play();
"));
$cell->nextFrame();
/* finally, add a bunch of the cells to the movie */
for ($x=0; $x<12; ++$x) {
for ($y=0; $y<8; ++$y) {
$i = $m->add($cell);
$i->moveTo(100*$x+50, 100*$y+50);
}
}
$m->nextFrame();
$m->add(new SWFAction("
gotoFrame(1);
play();
"));
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
]]>
</programlisting>
</example>
</para>
<para>
Same as above, but with nice colored balls...
<example>
<title><function>swfaction</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$m = new SWFMovie();
$m->setDimension(11000, 8000);
$m->setBackground(0x00, 0x00, 0x00);
$m->add(new SWFAction("
this.quality = 0;
/frames.visible = 0;
startDrag('/mouse', 1);
"));
// mouse tracking sprite
$t = new SWFSprite();
$i = $m->add($t);
$i->setName('mouse');
$g = new SWFGradient();
$g->addEntry(0, 0xff, 0xff, 0xff, 0xff);
$g->addEntry(0.1, 0xff, 0xff, 0xff, 0xff);
$g->addEntry(0.5, 0xff, 0xff, 0xff, 0x5f);
$g->addEntry(1.0, 0xff, 0xff, 0xff, 0);
// gradient shape thing
$s = new SWFShape();
$f = $s->addFill($g, SWFFILL_RADIAL_GRADIENT);
$f->scaleTo(0.03);
$s->setRightFill($f);
$s->movePenTo(-600, -600);
$s->drawLine(1200, 0);
$s->drawLine(0, 1200);
$s->drawLine(-1200, 0);
$s->drawLine(0, -1200);
// need to make this a sprite so we can multColor it
$p = new SWFSprite();
$p->add($s);
$p->nextFrame();
// put the shape in here, each frame a different color
$q = new SWFSprite();
$q->add(new SWFAction("gotoFrame(random(7)+1); stop();"));
$i = $q->add($p);
$i->multColor(1.0, 1.0, 1.0);
$q->nextFrame();
$i->multColor(1.0, 0.5, 0.5);
$q->nextFrame();
$i->multColor(1.0, 0.75, 0.5);
$q->nextFrame();
$i->multColor(1.0, 1.0, 0.5);
$q->nextFrame();
$i->multColor(0.5, 1.0, 0.5);
$q->nextFrame();
$i->multColor(0.5, 0.5, 1.0);
$q->nextFrame();
$i->multColor(1.0, 0.5, 1.0);
$q->nextFrame();
// finally, this one contains the action code
$p = new SWFSprite();
$i = $p->add($q);
$i->setName('frames');
$p->add(new SWFAction("
dx = (/:mousex-/:lastx)/3 + random(10)-5;
dy = (/:mousey-/:lasty)/3;
x = /:mousex;
y = /:mousey;
alpha = 100;
"));
$p->nextFrame();
$p->add(new SWFAction("
this.x = x;
this.y = y;
this.alpha = alpha;
x += dx;
y += dy;
dy += 3;
alpha -= 8;
"));
$p->nextFrame();
$p->add(new SWFAction("prevFrame(); play();"));
$p->nextFrame();
$i = $m->add($p);
$i->setName('frames');
$m->nextFrame();
$m->add(new SWFAction("
lastx = mousex;
lasty = mousey;
mousex = /mouse.x;
mousey = /mouse.y;
++num;
if (num == 11)
num = 1;
removeClip('char' & num);
duplicateClip(/frames, 'char' & num, num);
"));
$m->nextFrame();
$m->add(new SWFAction("prevFrame(); play();"));
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
]]>
</programlisting>
</example>
</para>
<!-- Serious syntax errors in example
<para>
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?)
<example>
<title><function>swfaction</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
/* sprite has one letter per frame */
$p = new SWFSprite();
$p->add(new SWFAction("stop();"));
$chars = 'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'1234567890!@#$%^&/*()_+-=/[]{}|;:,.<>?`~';
$f = new SWFFont("_sans");
for ($n=0; $nremove($i);
$t = new SWFTextField();
$t->setFont($f);
$t->setHeight(240);
$t->setBounds(600,240);
$t->align(SWFTEXTFIELD_ALIGN_CENTER);
$t->addString($c);
$i = $p->add($t);
$p->labelFrame($c);
$p->nextFrame();
}
/* hit region for button - the entire frame */
$s = new SWFShape();
$s->setFillStyle0($s->addSolidFill(0, 0, 0, 0));
$s->drawLine(600, 0);
$s->drawLine(0, 400);
$s->drawLine(-600, 0);
$s->drawLine(0, -400);
/* button checks for pressed key, sends sprite to the right frame */
$b = new SWFButton();
$b->addShape($s, SWFBUTTON_HIT);
for($n=0; $naddAction(new SWFAction("
setTarget('/char');
gotoFrame('$c');
"), SWFBUTTON_KEYPRESS($c));
}
$m = new SWFMovie();
$m->setDimension(600,400);
$i = $m->add($p);
$i->setName('char');
$i->moveTo(0,80);
$m->add($b);
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
]]>
</programlisting>
</example>
</para>
-->
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|