3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.flash.Component
17 * @extends Ext.Component
19 * A simple Component for displaying an Adobe Flash SWF movie. The movie will be sized and can participate
20 * in layout like any other Component.
22 * This component requires the third-party SWFObject library version 2.2 or above. It is not included within
23 * the ExtJS distribution, so you will have to include it into your page manually in order to use this component.
24 * The SWFObject library can be downloaded from the [SWFObject project page](http://code.google.com/p/swfobject)
25 * and then simply import it into the head of your HTML document:
27 * <script type="text/javascript" src="path/to/local/swfobject.js"></script>
31 * This component allows several options for configuring how the target Flash movie is embedded. The most
32 * important is the required {@link #url} which points to the location of the Flash movie to load. Other
33 * configurations include:
35 * - {@link #backgroundColor}
37 * - {@link #flashVars}
38 * - {@link #flashParams}
39 * - {@link #flashAttributes}
43 * var win = Ext.widget('window', {
44 * title: "It's a tiger!",
60 * Adobe provides a tool called [Express Install](http://www.adobe.com/devnet/flashplayer/articles/express_install.html)
61 * that offers users an easy way to upgrade their Flash player. If you wish to make use of this, you should set
62 * the static EXPRESS\_INSTALL\_URL property to the location of your Express Install SWF file:
64 * Ext.flash.Component.EXPRESS_INSTALL_URL = 'path/to/local/expressInstall.swf';
66 * @docauthor Jason Johnston <jason@sencha.com>
68 Ext.define('Ext.flash.Component', {
69 extend: 'Ext.Component',
70 alternateClassName: 'Ext.FlashComponent',
71 alias: 'widget.flash',
74 * @cfg {String} flashVersion
75 * Indicates the version the flash content was published for. Defaults to <tt>'9.0.115'</tt>.
77 flashVersion : '9.0.115',
80 * @cfg {String} backgroundColor
81 * The background color of the SWF movie. Defaults to <tt>'#ffffff'</tt>.
83 backgroundColor: '#ffffff',
87 * The wmode of the flash object. This can be used to control layering. Defaults to <tt>'opaque'</tt>.
88 * Set to 'transparent' to ignore the {@link #backgroundColor} and make the background of the Flash
94 * @cfg {Object} flashVars
95 * A set of key value pairs to be passed to the flash object as flash variables. Defaults to <tt>undefined</tt>.
99 * @cfg {Object} flashParams
100 * A set of key value pairs to be passed to the flash object as parameters. Possible parameters can be found here:
101 * http://kb2.adobe.com/cps/127/tn_12701.html Defaults to <tt>undefined</tt>.
105 * @cfg {Object} flashAttributes
106 * A set of key value pairs to be passed to the flash object as attributes. Defaults to <tt>undefined</tt>.
111 * The URL of the SWF file to include. Required.
115 * @cfg {String/Number} swfWidth The width of the embedded SWF movie inside the component. Defaults to "100%"
116 * so that the movie matches the width of the component.
121 * @cfg {String/Number} swfHeight The height of the embedded SWF movie inside the component. Defaults to "100%"
122 * so that the movie matches the height of the component.
127 * @cfg {Boolean} expressInstall
128 * True to prompt the user to install flash if not installed. Note that this uses
129 * Ext.FlashComponent.EXPRESS_INSTALL_URL, which should be set to the local resource. Defaults to <tt>false</tt>.
131 expressInstall: false,
135 * @type {Ext.Element}
136 * A reference to the object or embed element into which the SWF file is loaded. Only
137 * populated after the component is rendered and the SWF has been successfully embedded.
140 // Have to create a placeholder div with the swfId, which SWFObject will replace with the object/embed element.
141 renderTpl: ['<div id="{swfId}"></div>'],
143 initComponent: function() {
145 if (!('swfobject' in window)) {
146 Ext.Error.raise('The SWFObject library is not loaded. Ext.flash.Component requires SWFObject version 2.2 or later: http://code.google.com/p/swfobject/');
149 Ext.Error.raise('The "url" config is required for Ext.flash.Component');
157 * Fired when the Flash movie has been successfully embedded
158 * @param {Ext.flash.Component} this
164 * Fired when the Flash movie embedding fails
165 * @param {Ext.flash.Component} this
171 onRender: function() {
174 swfId = me.getSwfId();
176 me.renderData.swfId = swfId;
178 me.callParent(arguments);
181 allowScriptAccess: 'always',
182 bgcolor: me.backgroundColor,
187 allowedDomain: document.location.hostname
190 new swfobject.embedSWF(
196 me.expressInstall ? me.statics.EXPRESS_INSTALL_URL : undef,
200 Ext.bind(me.swfCallback, me)
206 * The callback method for handling an embedding success or failure by SWFObject
207 * @param {Object} e The event object passed by SWFObject - see http://code.google.com/p/swfobject/wiki/api
209 swfCallback: function(e) {
212 me.swf = Ext.get(e.ref);
214 me.fireEvent('success', me);
217 me.fireEvent('failure', me);
222 * Retrieve the id of the SWF object/embed element
224 getSwfId: function() {
225 return this.swfId || (this.swfId = "extswf" + this.getAutoId());
228 onSuccess: function() {
229 // swfobject forces visiblity:visible on the swf element, which prevents it
230 // from getting hidden when an ancestor is given visibility:hidden.
231 this.swf.setStyle('visibility', 'inherit');
234 onFailure: Ext.emptyFn,
236 beforeDestroy: function() {
240 swfobject.removeSWF(me.getSwfId());
249 * Sets the url for installing flash if it doesn't exist. This should be set to a local resource.
250 * See http://www.adobe.com/devnet/flashplayer/articles/express_install.html for details.
254 EXPRESS_INSTALL_URL: 'http:/' + '/swfobject.googlecode.com/svn/trunk/swfobject/expressInstall.swf'