projects @ biegel designs

projects, code & bugs

SWF-PHP Documentation (v. 0.9.1)

Other Documentation

Static methods

Methods

Properties

Static Methods

setPrefix

Description
static void setPrefix ( [ string $prefix = 'swfphp' ] )
Return Values
No value is returned.
Notes
This function sets the prefix that is used to generate automatic id and name attributes if you do not explicitly specify any. You must use the character set [A-Za-z][A-Za-z0-9_]+. Although the additional charaters .\*- are valid for the id and name attributes in (X)HTML, you cannot use these characters because they are javascript operators (the id property is used in the fscommand javascript wrapper functions).

The default value is swfphp.

Examples
<?php $swf = new SWF('example.swf'); $swf->createHtml() ; echo $swf->id ; // outputs 'swfphp0' ; SWF::setPrefix('valid_prefix'); $swf = new SWF('example.swf'); $swf->createHtml() ; echo $swf->id ; // outputs 'valid_prefix1' SWF::setPrefix('_invalid-prefix'); // error, invalid characters ?>
Back to top

setDoctype

Description
static void setDoctype ( [ string $doctype = 'XHTML 1.0' ] )
Return Values
No value is returned.
Notes
This method sets the doctype for the SWF-PHP class. The createHtml method will generate different code depending on which DTD you specify. Note that this method will simply search for the portion of the doctype that is necessary to determine output, so you can pass an entire <!DOCTYPE> declaration or merely the portion necessary. Specifically, SWF-PHP looks for the one of the following strings:
  • HTML 4.01
  • XHTML 1.0
  • XHTML 1.1
  • XHTML Basic 1.0
  • XHTML Basic 1.1
This method is not case sensitive.
Examples
<?php // the follow three statements all set SWF-PHP to a doctype of 'XHTML 1.1' SWF::setDoctype('XHTML 1.1'); SWF::setDoctype('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'); SWF::setDoctype('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'); // you'd never use the last one, but it is listed to demonstrate what SWF-PHP looks for SWF::setDoctype('HTML 5.0'); // error ?>
Back to top

Methods

__construct

Description
void __construct ( [string $src = '' [,mixed $width = '100%' [,mixed $height = '100%']]] )
Return Values
No value is returned.
Notes
You have the option of specifying the src and dimensions in the constructor. The constructor will trigger user errors if you pass invalid values for the parameters. See src and width / height for details.
Examples
<?php $swf = new SWF; $swf->src = 'example.swf'; $swf2 = new SWF('example.swf'); // specify src only $swf3 = new SWF('example.swf', 336, 280); // specific src & dimensions ?>
Back to top

createHtml

Description
bool createHtml ( void )
Return Values
Returns TRUE if no errors, FALSE otherwise.
Notes
Creates the HTML output without returning it. Useful if you want to make sure your SWF-PHP object will render correctly before you send any output to the browser. This method is called every time you access the html property.
Examples
<?php $swf = new SWF('example.swf'); if ( $swf->createHtml() ) { echo $swf->html ; } else { echo "Error rendering SWF-PHP object" ; } ?>
Back to top

Properties

$id

Default
null
Description
This is a string value that represents the id and name attributes in the <object> and <embed> tags. It is also used to identify the <div> container that surrounds the entire output.
Notes

The id and name attributes of the <object> tag will be set to this value, while the <div> container tag will have an id value of $id followed by _container.

The id must be unique. If you enter a value that has previously been used in your script, a fatal error will be triggered. If you do not enter a value, SWF-PHP will automatically assign a unique value for you. SWF-PHP maintains a static internal registry of all ids to prevent you from accidentally using the same id twice.

See the setPrefix method for the acceptable character set for this property.

Examples
<?php $swf = new SWF('example.swf'); $swf->id = "foo"; echo $swf->id; // outputs 'foo' $swf2 = new SWF('example.swf'); $swf2->id = "foo"; // fatal error $swf3 = new SWF('example.swf'); echo $swf3->id; // null $swf3->createHtml(); echo $swf3->id; // default output will be 'swfphp0' (see setPrefix above) ?>
Back to top

$src

Default
null
Description
This is the path & filename of the compiled SWF file.
Notes
The location of the actual SWF can be relative or absolute. If the path is relative, e.g. ../my-swfs/example.swf, keep in mind that the browser will consider the location of the file being requested over HTTP as the current path, which may or may not be the same file that actually instantiates the SWF class. Using an absolute path avoids this problem, e.g. http://www.example.com/my-swfs/example.swf.

This property can be passed to the constructor as well.

Examples
Example #1. Assume you're working in the public_html directory of example.com with a file called `index.php'. Your SWF file is located in public_html/my-swfs
/public_html/index.php: <?php $swf = new SWF('my-swfs/example.swf'); echo $swf->html ; // outputs normally ?>
Example #2. Now assume the SWF object is defined in an include file in public_html/my-swfs. The page being requested by the browser is still index.php in the public_html directory. You might assume you can just pass the filename directly because the include file and swf are in the same directory:
/public_html/my-swfs/swf-include.php: <?php $swf = new SWF('example.swf'); ?> /public_html/index.php: <?php require_once('my-swfs/swf-include.php'); echo $swf->html ; // output error `Movie not loaded' ?>
The SWF does not load because the browser is looking for 'http://www.example.com/example.swf'. You must always keep in mind that the location of the swf is always relative to the file being requested by the browser.

Back to top

$width, $height

Default
(string) "100%"
Description
The width and height of the SWF object.
Notes
The width and height of the SWF object have defaults of "100%", meaning they will span the dimensions of the immediate parent container. This is useful when you are using fluid dimensions in CSS and want your SWF to fill the space like any other DOM object. This is also useful for full-screen Flash apps that need to fill the entire browser window (or most of it).

These properties will accept either integer values or a percentage. If you enter any other value, SWF-PHP will typecast the value as an integer. This may produce unexpected results.

Examples
<?php $swf = new SWF('example.swf'); $swf->width = "90%" ; // swf spans the 90% of the width of its parent container $swf->height = 40; // swf is exactly 40 pixels tall echo $swf->html ; ?> <?php $swf = new SWF('example.swf'); $swf->width = "hello" ; // width is 0 $swf->height = "123cake" ; // height is 123 echo $swf->html ; ?>
Back to top

$alt

Default
null
Description
The $alt property can contain any HTML that you want to appear in the event that a user has javascript disabled AND cannot properly render the <object> tag.
Notes
This should rarely be needed as most users have javascript enabled or can render <object> tags. Be careful what you put in here. SWF-PHP does not do any error checking on this value and it will not stop you from prematurely closing the </noscript> or </object> tags.
Examples
<?php $swf = new SWF('example.swf'); $swf->alt = "<div>You really don't have javascript enabled AND can't render an object tag? Are you using Mosaic?</div>" ; ?>
Back to top

$flashVars

Default
(array) empty
Description
The FlashVars to pass to the SWF object. This is an associative array, with key-value pairs corresponding to variable names and values.
Notes
FlashVars provide a way to pass variables to a SWF object at runtime. FlashVars should typically be short; if you need to load a lot of data dynamically, it should be moved into an external XML file and loaded through AS3's XML loading functions. FlashVars are useful for instances where creating an XML file would be a waste of time (e.g. you only need to pass a single variable).

SWF-PHP will urlencode all the values; you do not need to urlencode them yourself.

Crucial points:

  1. Keep in mind that SWF-PHP will output all values as strings, so (bool) true will output as "1" and (bool) false will output as an empty string.
  2. The ActionScript virtual machine will interpret variables passed through FlashVars differently than PHP does. See the example below for more details.

Warning: you can manually set FlashVars by using the param property, but this is not advisable and may produce unexpected results.

Examples
Consider the following PHP file: <?php $swf = new SWF('example.swf'); $swf->flashVars = array( 'foo' => 1, 'bar' => 'www.google.com', 'baz' => 'Hello World!' 'foo2' => true, ) ; ?> SWF-PHP will output the following string for the FlashVars param: foo=1&amp;bar=www.google.com&amp;baz=Hello%20World%21&amp;foo2=1&amp; Your AS3 class might look like this: package com.example { import flash.display.MovieClip; public class Sample extends MovieClip { public var FlashVars:Object = new Object; public function Sample():void { var param:Object = LoaderInfo(this.root.loaderInfo).parameters; for ( var key:* in param ) { FlashVars[key] = param[key]; } trace(FlashVars['foo']); // outputs `1' trace(FlashVars['bar']); // outputs `www.google.com' trace(FlashVars['baz']); // outputs `Hello World!' trace(FlashVars['foo2']); // outputs `1' // (See note below) } } }

As you can see, between PHP, HTML, and AS3, a (bool)true can quickly become (string)"1". Type juggling between these languages can get tricky, so keep this in mind when using FlashVars.

Back to top

$param

Default
(array) empty
Description
This is an associative array corresponding to the <param> tags that control the behavior of the SWF in the browser. It should contain key-value pairs corresponding to the name and value attributes of the <param> tag.
Notes
Although the default value is an empty array, when you output the HTML, SWF-PHP will assign its own default values where necessary. You only need to explicitly define the values you want to override from the defaults. The table below lists valid parameters, the defaults and the possible values you can input. Note that all values are urlencoded.
Name Default Value Acceptable Values Notes
allowScriptAccess sameDomain always | never | sameDomain Not case-sensitive
allowFullScreen true true | false These are string literals
swliveconnect false true | false Whether the browser should start Java when loading the Flash Player for the first time. These are string literals
FlashVars empty Any string You should ALWAYS use the $flashVars property to set this parameter, though you can set it manually. If $flashVars is not empty, the createHtml() method will concatenate the values of $flashVars with $param['FlashVars'], which may produce unexpected results.
menu false true | false These are string literals
quality high low | autolow | autohigh | medium | high | best
bgcolor #ffffff Any valid hex color You cannot use CSS shorthand abbreviations, e.g. #ff0
wmode opaque opaque | transparent | window Controls appearance and positioning in the browser
scale showall showall | exactfit Note that if you use percentages in your width OR height, SWF-PHP will automatically toggle to 'exactfit' regardless of what you do.
You should note that the defaults SWF-PHP uses are slightly different from the defaults that Adobe uses. Additionally, there are other parameters that the Flash Player accepts, including play, loop and various other align attributes, but these are generally not needed and should be programmed in AS3 or CSS where appropriate (you should never leave playback controls up to HTML <param> tags and you should always keep presentation in CSS).

See Adobe LiveDocs for more details

Examples
<?php $swf = new SWF('example.swf'); $swf->param = array( 'menu' = 'true', 'wmode' = 'transparent', ) ; echo $swf->html ; // outputs a SWF object with right-click menus active and alpha transparency, with the rest of the the parameters set to the defaults ?>
Back to top

$fscommand

Default
(bool) false
Description
If set to true, SWF-PHP will output extra javascript code to handle fscommands. If set to false, the fscommand wrapper functions will not be output.
Notes
See the section on fscommands for more details.
Examples
<?php $swf = new SWF('example.swf'); $swf->fscommand = true; echo $swf->html ; // outputs fscommand javascript ?>
Back to top

$fscommandHandler

Default
null
Description
This property defines either a single wrapper function, or a set of functions.
Notes
Note that if you assign a value to this property, SWF-PHP will automatically set the fscommand property to (bool) true. See the section on fscommands for more details.
Examples
<?php $swf = new SWF('example.swf'); $swf->fscommand = true; $swf->fscommandHandler = 'handleMyCommands'; echo $swf->html ; // sends all fscommands to the javascript function `handleMyCommands' ?> <?php $swf = new SWF('example.swf'); $swf->fscommand = true; $swf->fscommandHandler = array( 'foo' => 'handler1', 'bar' => 'handler2', ) ; echo $swf->html ; // sends the command `foo' to javascript function `handler1' and command `bar' to javascript function `handler2' ?>
Back to top

$html

Default
null
Description
This property contains the HTML output for the SWF object, including javascript.
Notes
You cannot set this property manually; doing so will generate a fatal error. Every time you access this property, the createHtml method is called. This means you can change the HTML output of a SWP-PHP object if you echo this property more than once in a script.
Examples
<?php $swf = new SWF('example.swf'); echo $swf->html ; // calls createHtml, sends output $foo = $swf->html ; // assign the output to another variable $swf->width = 10 ; echo $swf->html ; // calls createHtml again, sends output (creating a very skinny SWF object) ?>
Back to top

$standards

Default
(bool) true
Description
When true, SWF-PHP will output standards-compliant HTML. When false, it will ouput the HTML code generated by the Adobe Flash IDE.
Notes
The non-standards code has not been extensively tested.
Examples
<?php $swf = new SWF('example.swf'); $swf->standards = false; echo $swf->html; // <embed> tags and clsid attributes galore ?>
Back to top