swfobject 2 masterclass

75
Bobby van der Sluis

Upload: bobby-van-der-sluis

Post on 22-May-2015

5.422 views

Category:

Technology


2 download

DESCRIPTION

My presentation for the 2008 online conference. Learn how to use SWFObject 2 to embed Adobe Flash content into web pages. This session will discuss all ins and outs, from the most basic hello world example to topics like Full Browser Flash, ActionScript-to-JavaScript communication, alternative content for people without Flash, SEO, Adobe Express Install and hacking around with the new SWFObject 2 JavaScript API.

TRANSCRIPT

Page 1: SWFObject 2 masterclass

Bobby van der Sluis

Page 2: SWFObject 2 masterclass

Embed SWF files into a Web page

Page 3: SWFObject 2 masterclass

Why SWFObject 2?

Web standardsAlternative contentFlash Player detectionAdobe Express InstallJavaScript APIEasy to use

Page 4: SWFObject 2 masterclass

Officially supported by Adobe

Page 5: SWFObject 2 masterclass
Page 6: SWFObject 2 masterclass

SWFObject 2 ZIP file

Page 7: SWFObject 2 masterclass

SWFObject 2 Generator

Publishing toolHTML pageAdobe AIR 1.0 application

Page 8: SWFObject 2 masterclass
Page 9: SWFObject 2 masterclass

One solution for everybody

Page 10: SWFObject 2 masterclass

Static publishing

HTML to embed SWF content and alternative contentUnobtrusive JavaScript to resolve issues

Page 11: SWFObject 2 masterclass

Dynamic publishing

HTML to define alternative contentUnobtrusive JavaScript to replace this with a SWF when the required Flash Player and JavaScript support is available

Page 12: SWFObject 2 masterclass

Static publishing

Embed mechanism doesn’t rely on JavaScriptClick to activate active content

Page 13: SWFObject 2 masterclass

Dynamic publishing

No click-to-activateEasy to integrate with scripted applications6% of your visitors will not have the required JavaScript support

Page 14: SWFObject 2 masterclass

Example 1: Hello World

Page 15: SWFObject 2 masterclass

Ingredients

swfobject.jsexpressInstall.swfSWFObject 2 Generator AIR 1.0test.swf

Page 16: SWFObject 2 masterclass

test.swf

300 x 120 px

Flash Player 6

v = $version;http://code.google.com/p/swfobject/wiki/test_suite

Page 17: SWFObject 2 masterclass

Static publishing

Page 18: SWFObject 2 masterclass
Page 19: SWFObject 2 masterclass
Page 20: SWFObject 2 masterclass
Page 21: SWFObject 2 masterclass

Dynamic publishing

Page 22: SWFObject 2 masterclass
Page 23: SWFObject 2 masterclass
Page 24: SWFObject 2 masterclass
Page 25: SWFObject 2 masterclass

Configuring SWF content

Page 26: SWFObject 2 masterclass
Page 27: SWFObject 2 masterclass
Page 28: SWFObject 2 masterclass
Page 29: SWFObject 2 masterclass
Page 30: SWFObject 2 masterclass

Adobe Express Install

Mechanism built into Flash PlayerPrompt to update outdated plug-in Required: Win/Mac and FP6r65+Optional in SWFObject

Page 31: SWFObject 2 masterclass
Page 32: SWFObject 2 masterclass
Page 33: SWFObject 2 masterclass
Page 34: SWFObject 2 masterclass

Alternative content

Page 35: SWFObject 2 masterclass
Page 36: SWFObject 2 masterclass
Page 37: SWFObject 2 masterclass
Page 38: SWFObject 2 masterclass

#1:

Translate SWF content into HTML content

that is accessible for people without the required

Flash Player or JavaScript support

Page 39: SWFObject 2 masterclass

#2:

Unobtrusive method to point visitors to

the Flash Player download page

Page 40: SWFObject 2 masterclass

#3:

Create search engine-friendly content

Page 41: SWFObject 2 masterclass

Doesn't Google index SWFs?

Google indexes both alternative and SWF contentNot all search engines index SWF contentSWF indexing is still limited: text and links only

Page 42: SWFObject 2 masterclass

The power of HTML content

1. Descriptive2. Hierarchy3. Semantics

Page 43: SWFObject 2 masterclass

Make sure that your alternative content

truly reflects your Flash content

Page 44: SWFObject 2 masterclass

Example 2:Full Browser Flash

Page 45: SWFObject 2 masterclass
Page 46: SWFObject 2 masterclass
Page 47: SWFObject 2 masterclass
Page 48: SWFObject 2 masterclass
Page 49: SWFObject 2 masterclass
Page 50: SWFObject 2 masterclass
Page 51: SWFObject 2 masterclass

Summarizing

1. 100% width and height 2. Add CSS to get rid of default

margin/padding and set the height of all parent containers for Firefox

Page 52: SWFObject 2 masterclass

Scaling and alignment

Manage from within SWFAlways use a resize handler

stage.scaleMode = StageScaleMode.NO_SCALE;stage.align = StageAlign.TOP_LEFT;

stage.addEventListener(Event.RESIZE, resizeHandler);

function resizeHandler(event:Event):void { // e.g. center stuff}

Page 53: SWFObject 2 masterclass

Example 3:JS to AS communication using External Interface

Page 54: SWFObject 2 masterclass

External Interface

Allows two-way communication between SWF and an HTML page

Flash Player 8+ActionScript 2

http://livedocs.adobe.com/flash/8/main/00002200.html

Page 55: SWFObject 2 masterclass

The example

JavaScript to ActionScriptTo register an AS method as callable from JS:addCallback(methodName:String, instance:Object, method:Function):Boolean

Page 56: SWFObject 2 masterclass
Page 57: SWFObject 2 masterclass
Page 58: SWFObject 2 masterclass
Page 59: SWFObject 2 masterclass
Page 60: SWFObject 2 masterclass
Page 61: SWFObject 2 masterclass
Page 62: SWFObject 2 masterclass

Upload your files

Page 63: SWFObject 2 masterclass
Page 64: SWFObject 2 masterclass
Page 65: SWFObject 2 masterclass

Summarizing

1. Register an AS method as callable from JS

2. Add an ID to your object element3. Call your AS method from JS

Page 66: SWFObject 2 masterclass

Static publishing

Uses nested objectsAdd an ID to your outer object element onlyTo reference your active object element use:swfobject.getObjectById(objectIdStr)

Page 67: SWFObject 2 masterclass

Using the JavaScript API

Page 68: SWFObject 2 masterclass

SWFObject JavaScript API

Focuses on publishing SWFs and detecting Flash Player

Lets developers reuse SWFObject's internal functions

http://code.google.com/p/swfobject/wiki/api

Page 69: SWFObject 2 masterclass

10 methodsswfobject.registerObject(...)swfobject.getObjectById(...)

swfobject.embedSWF(...)swfobject.createSWF(...)

swfobject.getFlashPlayerVersion()swfobject.hasFlashPlayerVersion(...)

swfobject.addLoadEvent(...)swfobject.addDomLoadEvent(...)

swfobject.createCSS(...)

swfobject.getQueryParamValue(...)

Page 70: SWFObject 2 masterclass

Example 4:Getting Flash Player version

Page 71: SWFObject 2 masterclass

getFlashPlayerVersion

Returns a JavaScript object that contains the major, minor and release version numbersMAC 9,0,124,0

Page 72: SWFObject 2 masterclass

The JavaScript code<script type="text/javascript" src="swfobject.js"></script>

<script type="text/javascript">

var playerVersion = swfobject.getFlashPlayerVersion();

var output = "You have Flash player " +

playerVersion.major + "." +

playerVersion.minor + "." +

playerVersion.release + " installed";

alert(output);

</script>

Page 73: SWFObject 2 masterclass

The result

Page 74: SWFObject 2 masterclass

Thank you!