SWFbutton

(PHP 4 >= 4.0.5)

SWFbutton -- Creates a new Button

Description

object swfbutton ( void )

Warning

This function is EXPERIMENTAL. 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.

swfbutton() creates a new Button. Roll over it, click it, see it call action code. Swank.

SWFButton has the following methods : swfbutton->addshape(), swfbutton->setup(), swfbutton->setover() swfbutton->setdown(), swfbutton->sethit() swfbutton->setaction() and swfbutton->addaction().

This simple example will show your usual interactions with buttons : rollover, rollon, mouseup, mousedown, noaction.

Example 1. swfbutton() example

<?php

  $f
= new SWFFont("_serif");

  
$p = new SWFSprite();

  function
label($string)
  {
    global
$f;

    
$t = new SWFTextField();
    
$t->setFont($f);
    
$t->addString($string);
    
$t->setHeight(200);
    
$t->setBounds(3200, 200);
    return
$t;
  }
  
  function
addLabel($string)
  {
    global
$p;

    
$i = $p->add(label($string));
    
$p->nextFrame();
    
$p->remove($i);
  }

  
$p->add(new SWFAction("stop();"));
  
addLabel("NO ACTION");
  
addLabel("SWFBUTTON_MOUSEUP");
  
addLabel("SWFBUTTON_MOUSEDOWN");
  
addLabel("SWFBUTTON_MOUSEOVER");
  
addLabel("SWFBUTTON_MOUSEOUT");
  
addLabel("SWFBUTTON_MOUSEUPOUTSIDE");
  
addLabel("SWFBUTTON_DRAGOVER");
  
addLabel("SWFBUTTON_DRAGOUT");

  function
rect($r, $g, $b)
  {
    
$s = new SWFShape();
    
$s->setRightFill($s->addFill($r, $g, $b));
    
$s->drawLine(600, 0);
    
$s->drawLine(0, 600);
    
$s->drawLine(-600, 0);
    
$s->drawLine(0, -600);

    return
$s;
  }

  
$b = new SWFButton();
  
$b->addShape(rect(0xff, 0, 0), SWFBUTTON_UP | SWFBUTTON_HIT);
  
$b->addShape(rect(0, 0xff, 0), SWFBUTTON_OVER);
  
$b->addShape(rect(0, 0, 0xff), SWFBUTTON_DOWN);

  
$b->addAction(new SWFAction("setTarget('/label'); gotoFrame(1);"),
            
SWFBUTTON_MOUSEUP);

  
$b->addAction(new SWFAction("setTarget('/label'); gotoFrame(2);"),
        
SWFBUTTON_MOUSEDOWN);

  
$b->addAction(new SWFAction("setTarget('/label'); gotoFrame(3);"),
        
SWFBUTTON_MOUSEOVER);

  
$b->addAction(new SWFAction("setTarget('/label'); gotoFrame(4);"),
        
SWFBUTTON_MOUSEOUT);

  
$b->addAction(new SWFAction("setTarget('/label'); gotoFrame(5);"),
        
SWFBUTTON_MOUSEUPOUTSIDE);

  
$b->addAction(new SWFAction("setTarget('/label'); gotoFrame(6);"),
        
SWFBUTTON_DRAGOVER);

  
$b->addAction(new SWFAction("setTarget('/label'); gotoFrame(7);"),
        
SWFBUTTON_DRAGOUT);

  
$m = new SWFMovie();
  
$m->setDimension(4000, 3000);

  
$i = $m->add($p);
  
$i->setName("label");
  
$i->moveTo(400, 1900);

  
$i = $m->add($b);
  
$i->moveTo(400, 900);

  
header('Content-type: application/x-shockwave-flash');
  
$m->output();
?>

This simple example will enables you to drag draw a big red button on the windows. No drag-and-drop, just moving around.

Example 2. swfbutton->addaction() example

<?php

  $s
= new SWFShape();
  
$s->setRightFill($s->addFill(0xff, 0, 0));
  
$s->drawLine(1000,0);
  
$s->drawLine(0,1000);
  
$s->drawLine(-1000,0);
  
$s->drawLine(0,-1000);

  
$b = new SWFButton();
  
$b->addShape($s, SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);

  
$b->addAction(new SWFAction("startDrag('/test', 0);"), // '0' means don't lock to mouse
        
SWFBUTTON_MOUSEDOWN);

  
$b->addAction(new SWFAction("stopDrag();"),
        
SWFBUTTON_MOUSEUP | SWFBUTTON_MOUSEUPOUTSIDE);

  
$p = new SWFSprite();
  
$p->add($b);
  
$p->nextFrame();

  
$m = new SWFMovie();
  
$i = $m->add($p);
  
$i->setName('test');
  
$i->moveTo(1000,1000);

  
header('Content-type: application/x-shockwave-flash');
  
$m->output();
?>

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();
?>