The SWFMovie class
(PHP 5 <= 5.3.0, PECL ming SVN)
Введение
SWFMovie is a movie object representing an SWF movie.
Обзор классов
Содержание
- SWFMovie::add — Adds any type of data to a movie
- SWFMovie::addExport — Описание
- SWFMovie::addFont — Описание
- SWFMovie::__construct — Creates a new movie object, representing an SWF version 4 movie
- SWFMovie::importChar — Описание
- SWFMovie::importFont — Описание
- SWFMovie::labelFrame — Labels a frame
- SWFMovie::nextFrame — Moves to the next frame of the animation
- SWFMovie::output — Dumps your lovingly prepared movie out
- SWFMovie::remove — Removes the object instance from the display list
- SWFMovie::save — Saves the SWF movie in a file
- SWFMovie::saveToFile — Описание
- SWFMovie::setbackground — Sets the background color
- SWFMovie::setDimension — Sets the movie's width and height
- SWFMovie::setFrames — Sets the total number of frames in the animation
- SWFMovie::setRate — Sets the animation's frame rate
- SWFMovie::startSound — Описание
- SWFMovie::stopSound — Описание
- SWFMovie::streamMP3 — Streams a MP3 file
- SWFMovie::writeExports — Описание
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Генерация нетекстовых MIME форматов
- Введение
- Установка и настройка
- Предопределенные константы
- Примеры
- Ming Функции
- The SWFAction class
- The SWFBitmap class
- The SWFButton class
- The SWFDisplayItem class
- The SWFFill class
- The SWFFont class
- The SWFFontChar class
- The SWFGradient class
- The SWFMorph class
- The SWFMovie class
- The SWFPrebuiltClip class
- The SWFShape class
- The SWFSound class
- The SWFSoundInstance class
- The SWFSprite class
- The SWFText class
- The SWFTextField class
- The SWFVideoStream class
Коментарии
<?php
$myShape1=new SWFShape();
$myShape1->setLine(5,0,0,255);
$myShape1->setRightFill(255,255,0);
$myShape1->movePen(-30,-30);
$myShape1->drawLine(60,0);
$myShape1->drawLine(0,60);
$myShape1->drawLine(-60,0);
$myShape1->drawLine(0,-60);
$myMovie=new SWFMovie();
$myMovie->setDimension(460,80);
$myMovie->setBackground(255,0,0);
$movingSquare=$myMovie->add($myShape1);
$movingSquare->moveTo(40,40);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->nextFrame();
$movingSquare->move(40,0);
$myMovie->save("lesson.swf");
?>
Sachin Akhani
http://www.askyp.com
<?php
// php ming swf flash movie example --
// this routine simply adds a shadow, text, and movement to a rectangle shape.
// for a dissolve effect using swfmorph, see this add'l note:
// function.swfmorph.construct
$lineweight = 3;
$linered = 102;
$linegreen = 102;
$lineblue = 255;
$fillred = 204;
$fillgreen = 204;
$fillblue = 255;
$rectlinelen = 200;
$shadowred = 153;
$shadowgreen = 153;
$shadowblue = 153;
$shadowoffset = 3;
$x = 100;
$y = 150;
$m = new SWFMovie();
$m->setDimension(640,480);
$m->setBackground(235,235,235);
$m->setRate(65);
$is = $m->add(shadowrectShape(true));
$i = $m->add(rectShape(true));
$text = "Shadow Play...";
$its = $m->add(textField($text, 15, $shadowred, $shadowgreen, $shadowblue));
$it = $m->add(textField($text, 15, $linered-25, $linegreen, $lineblue));
$is->moveTo($x+$shadowoffset,$y+$shadowoffset);
$i->moveTo($x,$y); // starting x,y for rectangle
$its->moveTo($x+15+1,$y+15+1); // only a minimal shadow for text...
$it->moveTo($x+15,$y+15);
for ($n=0; $n < 75; $n++) {
$is->move(2.05, 0.05); // rectangle's shadow, lengthens as it moves
$i->move(2,0); // original rectangle
$its->move(2, 0.01); // text shadow
$it->move(2,0); // text
$m->nextFrame();
}
$m->add(new SWFAction("stop();"));
$m->nextFrame();
// $m->save("shadow.swf");
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
<?php
function rectShape($addfill) {
global $lineweight, $linered, $linegreen, $lineblue;
global $fillred, $fillgreen, $fillblue, $rectlinelen;
$s = new SWFShape();
$s->setLine($lineweight, $linered, $linegreen, $lineblue);
if ($addfill) {
$s->setRightFill($s->addFill($fillred, $fillgreen, $fillblue));
}
$s->drawLine($rectlinelen, 0);
$s->drawLine(0, $rectlinelen);
$s->drawLine(-$rectlinelen, 0);
$s->drawLine(0, -$rectlinelen);
return $s;
}
function shadowrectShape($addfill) {
global $lineweight, $rectlinelen;
global $shadowoffset, $shadowred, $shadowgreen, $shadowblue;
$s = new SWFShape();
$s->setLine($lineweight, $shadowred, $shadowgreen, $shadowblue);
if ($addfill) {
$s->setRightFill($s->addFill($shadowred, $shadowgreen, $shadowblue));
}
$s->drawLine($rectlinelen+$shadowoffset, 0);
$s->drawLine(0, $rectlinelen+$shadowoffset);
$s->drawLine(-$rectlinelen-$shadowoffset, 0);
$s->drawLine(0, -$rectlinelen-$shadowoffset);
return $s;
}
function textField($strtext, $intheight, $textred, $textgreen, $textblue) {
$t = new SWFTextField();
$t->setFont(new SWFFont('Default'));
// or try this instead:
// $t = new SWFText();
// $f = new SWFFont("Bitstream Vera Sans.fdb");
// $t->setFont($f);
$t->setColor($textred, $textgreen, $textblue);
$t->addString($strtext);
$t->setHeight($intheight);
return $t;
}
?>
<?php
// php ming swf flash movie example #2 --
// this routine displays several wipe/fade transitional effects
$f = new SWFFont("Bitstream Vera Serif.fdb");
$m = new SWFMovie();
$m->setDimension(640, 480);
$m->setBackground(0, 255, 153);
$m->setRate(9);
$p = movieclip("First...", 0, 255, 255, 100, 50, 25, 7);
$i = $m->add($p);
$p = movieclip("Second...", 102, 0, 102, 100, 170, 18, 5);
$i = $m->add($p);
$p = movieclip("Third...", 255, 0, 51, 100, 290, 30, 6);
$i = $m->add($p);
// $m->save("wfeffect.swf");
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
<?php
function movieclip($txt, $r, $g, $b, $x, $y, $sv, $mv) {
global $f;
$s = new SWFShape();
$s->setLine(1,0,0,255); // (line weight, r, g, b)
$s->setRightFill(255,255,0);
$s->drawLine(170,0);
$s->drawLine(0,60);
$s->drawLine(-170,0);
$s->drawLine(0,-60);
$t = new SWFText();
$t->setFont($f);
$t->setColor($r, $g, $b);
$t->setHeight(17);
$t->addString($txt);
$p = new SWFSprite();
$is = $p->add($s);
// works with images also:
// $is = $p->add(new SWFBitMap(fopen("/images/yourbmp.jpg", "rb")));
$it = $p->add($t);
$is->moveTo($x, $y);
$it->moveTo($x+10, $y+20);
// adjust movement left with a compensating move
// right ($i->move()), to change look of this effect:
// note: setting the scaleTo() $y parameter to 0 didn't help(?)
// fixed in later versions? only tested with Ming 0.3beta1.
$scaleLeftValue = $sv;
$moveRightValue = $scaleLeftValue/$mv;
for ($n=1; $n < $scaleLeftValue; $n++) {
$is->scaleTo(1-($n/$scaleLeftValue), 1);
$it->scaleTo(1-($n/$scaleLeftValue), 1);
$is->move($moveRightValue, 0);
// fade text color to add to effect:
if ($n <= 10) {
$it->addColor(10*$n, 10*$n, 10*$n);
}
// try to keep text in bounds
if ($n < $scaleLeftValue - 2) {
$it->move($moveRightValue, 0);
}
$p->nextframe();
}
$p->remove($is); // remove() causes item to disappear
$p->remove($it); // which is exactly what we want here
$p->nextFrame();
$p->add(new SWFAction("stop();"));
$p->nextFrame();
return $p;
}
?>
<?php
// php ming 'challenge response' style text to graphics routine --
// (example only; any use for input validation is up to you, however
// this image can be displayed on text pages in an html iframe)
$f = new SWFFont("Bitstream Vera Serif.fdb");
$m = new SWFMovie();
$m->setDimension(500, 150);
$m->setBackground(255, 255, 255);
for ($r=0; $r < 6; $r++) {
// random char selected from range: '2-9', 'A-Z', 'a-z'
switch (rand(0,2)) {
case 0:
$c = chr(rand(50,57));
break;
case 1:
$c = chr(rand(65,90));
break;
case 2:
$c = chr(rand(97,122));
break;
}
$p = convertchar($c);
$i = $m->add($p);
}
$i->setDepth(1);
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
<?php
function convertchar($txt) {
global $f;
static $x=10, $y=5;
$s = new SWFShape();
$s->setLine(rand(0,1),125,125,200); // (line weight, r, g, b)
$s->drawLine(rand(15,25),0);
$t = new SWFText();
$t->setFont($f);
$t->setColor(15, 15, 195);
$t->setHeight(40);
$t->addString($txt);
$p = new SWFSprite();
$is = $p->add($s);
$it = $p->add($t);
$is->move($x,$y); // lines thru char
$it->move($x,$y+8);
$x+=75;
// all chars adjusted in a slightly random manner
$rs = rand(-1,1);
for ($n=0; $n < 3; $n++) {
$it->scaleTo($n, 1);
$is->scaleTo($n, 1);
$it->rotate($rs);
$is->rotate($rs);
$it->skewx(-$rs/10);
$is->skewx(-$rs/10);
$it->skewy($rs/10);
$is->skewy($rs/10);
$p->nextframe();
}
$p->add(new SWFAction("stop();"));
$p->nextFrame();
return $p;
}
?>