2013-07-17 46 views
0

我想創建一個ExtJS應用程序來創建基於XML文件的表面,然後能夠通過鼠標在這些表面上添加精靈。我正在通過參數來創建曲面和精靈的實際功能有點麻煩,這些參數可以從前面列舉的源中獲得。當我在JS控制檯中檢查tham的值時,我創建的對象會返回undefined。我沒有在它報告的JS中有任何錯誤或警告。這裏是代碼:ExtJS表面和精靈創建函數

Ext.ns('myNameSpace');//create namespace to hold all variables 
    myNameSpace = { 
     init: function(){//initialize namespace 
      function surfaceCreator(name){//create surface based on parameter 
       var name = Ext.create('Ext.draw.Component', { 
        viewBox: false 
       }); 
       return name; 
      } 
      function spriteCreator(surfaceName,sprite,posX,posY){//draw sprite based on parameters 
       var sprite = Ext.create('Ext.draw.Sprite', { 
        type: 'circle', 
        x: posX, 
        y: posY, 
        radius: 25, 
        surface: surfaceName.surface, 
        fill: '#cc5' 
       });sprite.show(true); 
      } 
      var mySurface = 'mySurface';//this could be an xml value 
      var myCircle = 'myCircle';//this could be determined by numbering each one that is created. 
      var myActualSurface = surfaceCreator(mySurface);//call function to create surface and return surface name as an object 
      spriteCreator(myActualSurface,myCircle,20,20);//call function to create sprite on specified surface. Also, I could use the mouse coordinates to determine where the sprite should be drawn and make this trigger on 'click'. 
      var myWin = Ext.create('Ext.Window', {// Create a window to house the surfaces 
       width: 800, 
       resizeable: false, 
       height: 600, 
       layout: 'fit', 
       items: myActualSurface//This seems to be undefined somehow and I'm not sure why, as it is defined up above. 
      }).show(); 
     } 
    } 
Ext.onReady(myNameSpace.init,myNameSpace);//render namespace when webpage is ready. 

如果我能得到一些關於可能發生的事情的第二意見,我會很高興。如果有人有解決方案(可能是我只是使用不正確的東西),我會欣喜若狂。感謝您的時間和考慮。

回答

0

我覺得這裏的主要問題是 「表面」 屬性,是指:

surfaceName.add(sprite); 

OR

var sprite = Ext.create('Ext.draw.Sprite', { 
        type: 'circle', 
        x: posX, 
        y: posY, 
        radius: 25, 
        // surface: surfaceName.surface, >> omit this line 
        fill: '#cc5' 
       }); 
{ 
xtype:'drawcomponent', 
items:[sprite] 
} 
http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.draw.Sprite

可以使用下面的符號加雪碧的表面