Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / src / widgets / chart / FlashComponent.js
1 /*!
2  * Ext JS Library 3.0.0
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 {String} url
34      * The URL of the chart to include. Defaults to <tt>undefined</tt>.
35      */
36     url: undefined,
37     swfId : undefined,
38     swfWidth: '100%',
39     swfHeight: '100%',
40
41     /**
42      * @cfg {Boolean} expressInstall
43      * True to prompt the user to install flash if not installed. Note that this uses
44      * Ext.FlashComponent.EXPRESS_INSTALL_URL, which should be set to the local resource. Defaults to <tt>false</tt>.
45      */
46     expressInstall: false,
47
48     initComponent : function(){
49         Ext.FlashComponent.superclass.initComponent.call(this);
50
51         this.addEvents('initialize');
52     },
53
54     onRender : function(){
55         Ext.FlashComponent.superclass.onRender.apply(this, arguments);
56
57         var params = {
58             allowScriptAccess: 'always',
59             bgcolor: this.backgroundColor,
60             wmode: this.wmode
61         }, vars = {
62             allowedDomain: document.location.hostname,
63             elementID: this.getId(),
64             eventHandler: 'Ext.FlashEventProxy.onEvent'
65         };
66
67         new swfobject.embedSWF(this.url, this.id, this.swfWidth, this.swfHeight, this.flashVersion,
68             this.expressInstall ? Ext.FlashComponent.EXPRESS_INSTALL_URL : undefined, vars, params);
69
70         this.swf = Ext.getDom(this.id);
71         this.el = Ext.get(this.swf);
72     },
73
74     getSwfId : function(){
75         return this.swfId || (this.swfId = "extswf" + (++Ext.Component.AUTO_ID));
76     },
77
78     getId : function(){
79         return this.id || (this.id = "extflashcmp" + (++Ext.Component.AUTO_ID));
80     },
81
82     onFlashEvent : function(e){
83         switch(e.type){
84             case "swfReady":
85                 this.initSwf();
86                 return;
87             case "log":
88                 return;
89         }
90         e.component = this;
91         this.fireEvent(e.type.toLowerCase().replace(/event$/, ''), e);
92     },
93
94     initSwf : function(){
95         this.onSwfReady(!!this.isInitialized);
96         this.isInitialized = true;
97         this.fireEvent('initialize', this);
98     },
99
100     beforeDestroy: function(){
101         if(this.rendered){
102             swfobject.removeSWF(this.swf.id);
103         }
104         Ext.FlashComponent.superclass.beforeDestroy.call(this);
105     },
106
107     onSwfReady : Ext.emptyFn
108 });
109
110 /**
111  * Sets the url for installing flash if it doesn't exist. This should be set to a local resource.
112  * @static
113  * @type String
114  */
115 Ext.FlashComponent.EXPRESS_INSTALL_URL = 'http:/' + '/swfobject.googlecode.com/svn/trunk/swfobject/expressInstall.swf';
116
117 Ext.reg('flash', Ext.FlashComponent);