View Full Version : Basic object creation. How to customize a window?

21 Oct 2011, 4:24 AM
Starting point. This works. Guess I swiped it from an example.

winPlayer = Ext.create('widget.window', {
title: 'Layout Window',
closable: true,
closeAction: 'hide',
width: 600,
minWidth: 350,
height: 350,
layout: 'fit',
html: '<div id="flowplayer"></div>'

This plays a video in a floating window. Very nice.
Now I want more of them. Time to make this into a component of my own.
I understand in javascript I cannot have a "class definition".
I'll get a kind of prototype object from Ext.define, and I'll be able to instantiate with Ext.create

I move it into a file: app/window/Winplayer.js and the loader requires it. Good.

How to instantiate an this object?
I read the "new" keyword is only for simple javascript object.
I read we want to stick with Ext.define and Ext.create

But I see most components have "Instance Methods" like "new Ext.window.Window"
This does not look like method signature at all? It's using the new keyword of the language?

I've been trying all sorts of things. Currently my window looks like this:

Ext.define('v10.window.Winplayer', {
extend: 'widget.window',
listeners: {
show: this.onShow
initComponent: function() {
console.log('initComponent winplayer');
Ext.apply(this, {
title: 'Play Me',
closable: true,
closeAction: 'hide',
width: 640,
height: 480,
minHeight: 260,
minWidth: 320,
layout: 'fit',
html: '<div id="winplayer"></div>',
onShow: function(t,e) {
console.log('on show')
console.log('winplayer created')

In the app...
var wp = Ext.create('widget.winplayer')

throws no errors and allows me to set a title.

But I can't call the show() method (it is not defined).
I can see under Chrome that my instance isn't at all the same as the sample one.
Truly missing all the goop that I expected to inherit from a window.

Obviously I have misunderstood something. But what?
Is window a peculiar object? Have I messed the widget alias thing?
Which sample/example can I look at now...?

21 Oct 2011, 7:27 AM
you should extend the Ext class, not its widget name... so in your code use:

extend: 'Ext.window.Window'

and you will be near...

21 Oct 2011, 8:01 AM
Perfect thank you.