Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / src / widgets / chart / FlashComponent.js
1 /*!
2  * Ext JS Library 3.0.3
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8  * @class Ext.FlashComponent
9  * @extends Ext.BoxComponent
10  * @constructor
11  * @xtype flash
12  */
13 Ext.FlashComponent = Ext.extend(Ext.BoxComponent, {
14     /**
15      * @cfg {String} flashVersion
16      * Indicates the version the flash content was published for. Defaults to <tt>'9.0.45'</tt>.
17      */
18     flashVersion : '9.0.45',
19
20     /**
21      * @cfg {String} backgroundColor
22      * The background color of the chart. Defaults to <tt>'#ffffff'</tt>.
23      */
24     backgroundColor: '#ffffff',
25
26     /**
27      * @cfg {String} wmode
28      * The wmode of the flash object. This can be used to control layering. Defaults to <tt>'opaque'</tt>.
29      */
30     wmode: 'opaque',
31     
32     /**
33      * @cfg {Object} flashVars
34      * A set of key value pairs to be passed to the flash object as flash variables. Defaults to <tt>undefined</tt>.
35      */
36     flashVars: undefined,
37     
38     /**
39      * @cfg {Object} flashParams
40      * A set of key value pairs to be passed to the flash object as parameters. Possible parameters can be found here:
41      * http://kb2.adobe.com/cps/127/tn_12701.html Defaults to <tt>undefined</tt>.
42      */
43     flashParams: undefined,
44
45     /**
46      * @cfg {String} url
47      * The URL of the chart to include. Defaults to <tt>undefined</tt>.
48      */
49     url: undefined,
50     swfId : undefined,
51     swfWidth: '100%',
52     swfHeight: '100%',
53
54     /**
55      * @cfg {Boolean} expressInstall
56      * True to prompt the user to install flash if not installed. Note that this uses
57      * Ext.FlashComponent.EXPRESS_INSTALL_URL, which should be set to the local resource. Defaults to <tt>false</tt>.
58      */
59     expressInstall: false,
60
61     initComponent : function(){
62         Ext.FlashComponent.superclass.initComponent.call(this);
63
64         this.addEvents('initialize');
65     },
66
67     onRender : function(){
68         Ext.FlashComponent.superclass.onRender.apply(this, arguments);
69
70         var params = Ext.apply({
71             allowScriptAccess: 'always',
72             bgcolor: this.backgroundColor,
73             wmode: this.wmode
74         }, this.flashParams), vars = Ext.apply({
75             allowedDomain: document.location.hostname,
76             elementID: this.getId(),
77             eventHandler: 'Ext.FlashEventProxy.onEvent'
78         }, this.flashVars);
79
80         new swfobject.embedSWF(this.url, this.id, this.swfWidth, this.swfHeight, this.flashVersion,
81             this.expressInstall ? Ext.FlashComponent.EXPRESS_INSTALL_URL : undefined, vars, params);
82
83         this.swf = Ext.getDom(this.id);
84         this.el = Ext.get(this.swf);
85     },
86
87     getSwfId : function(){
88         return this.swfId || (this.swfId = "extswf" + (++Ext.Component.AUTO_ID));
89     },
90
91     getId : function(){
92         return this.id || (this.id = "extflashcmp" + (++Ext.Component.AUTO_ID));
93     },
94
95     onFlashEvent : function(e){
96         switch(e.type){
97             case "swfReady":
98                 this.initSwf();
99                 return;
100             case "log":
101                 return;
102         }
103         e.component = this;
104         this.fireEvent(e.type.toLowerCase().replace(/event$/, ''), e);
105     },
106
107     initSwf : function(){
108         this.onSwfReady(!!this.isInitialized);
109         this.isInitialized = true;
110         this.fireEvent('initialize', this);
111     },
112
113     beforeDestroy: function(){
114         if(this.rendered){
115             swfobject.removeSWF(this.swf.id);
116         }
117         Ext.FlashComponent.superclass.beforeDestroy.call(this);
118     },
119
120     onSwfReady : Ext.emptyFn
121 });
122
123 /**
124  * Sets the url for installing flash if it doesn't exist. This should be set to a local resource.
125  * @static
126  * @type String
127  */
128 Ext.FlashComponent.EXPRESS_INSTALL_URL = 'http:/' + '/swfobject.googlecode.com/svn/trunk/swfobject/expressInstall.swf';
129
130 Ext.reg('flash', Ext.FlashComponent);