2010-06-09 81 views
0

最近我試圖用JSFL做一些實驗性的事情,而且我想知道是否有可能在組件(我製作的)或動畫片段從舞臺上的庫中拖出時監聽事件。在JSFL中拖放movieclip事件? (Flash IDE)

我想創建一些東西,我會得到一個組件,並將其放在MC上。當組件被放置在mc上時,組件將在一些var中保存mc作爲引用。

也許事件並不是這樣,但我不知道如果這是可能的或如何做到另一種方式。我希望有人能幫助我開始

THX提前

回答

0

雖然可以listen for document events,我不認爲你可以拖放組件到MovieClip並獲得影片剪輯的參考。

你可以做的事情是編寫一個命令,首先存儲所選影片剪輯的引用,然後使用mc參數設置將該組件添加到舞臺。

下面是使用Button組件的一個簡單示例。命令get的選定mc的名稱,然後添加一個按鈕,並將mc的名稱設置爲按鈕名稱。

var doc = fl.getDocumentDOM(); 
var mc = doc.selection[0];//get the mc 
doc.selectNone(); 

//add the component 
fl.componentsPanel.addItemToDocument({x:mc.x, y:mc.y}, "User Interface", "Button"); 
//setup parameter 
//use this if you don't know the paramater's index in the list 
setComponentValueByParamName(doc.selection[0],'label',mc.name); 
//otherhise you can get away with 
//doc.selection[0].parameters[2].value = mc.name; 

//returns true if the param was found and value was set, otherwise returns false 
function setComponentValueByParamName(component,param,value){ 
    for(var i = 0 ; i < component.parameters.length; i++){ 
     if(component.parameters[i].name == param){ 
      component.parameters[i].value = value; 
      return true; 
     } 
    } 
    return false; 
} 

看一看fl.componentPanelComponentInstanceParameter,以獲得更好的畫面。

HTH