views:

54

answers:

1

Lately im trying to do some experimental things with JSFL, and i was wondering if it is possible to listener for an event when a component (that i have made) or movieclip is dragged from library on the stage.

i want to create something that i'll get a component and drop it on a mc. when the component is dropped on the mc the component will save the mc as a reference in some var.

maybe with events isnt the way to go but i have no clue if this is possible or how to do it another way. i hope someone can help me get started

thx in advance

A: 

Although you can listen for document events, I don't think you can drop a component on to a movieclip and get the reference of the movieclip.

What you could do though is write a command that first stores the reference of the selected movie clip and then adds the component to the stage, with the mc parameter setup.

Here's a quick example using the Button component. The command get's the name of the selected mc then adds a button and sets the name of the mc as the Button name.

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;
}

Have a look at fl.componentPanel, ComponentInstance and Parameter to get a better picture.

HTH

George Profenza