JSFL 中的拖放影片剪辑事件? (闪存IDE)

发布于 2024-09-05 04:59:58 字数 206 浏览 8 评论 0原文

最近我尝试用 JSFL 做一些实验性的事情,我想知道当一个组件(我制作的)或影片剪辑从舞台上的库中拖动时是否可以监听事件。

我想创建一些东西,我将获得一个组件并将其放在MC上。当组件被放到 mc 上时,组件会将 mc 保存为某个变量中的引用。

也许事件不是解决办法,但我不知道这是否可能或如何以其他方式做到这一点。我希望有人可以帮助我

提前开始,谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷情妓 2024-09-12 04:59:58

虽然您可以监听文档事件,但我不您不认为可以将组件放到影片剪辑上并获取影片剪辑的引用。

您可以做的是编写一个命令,首先存储所选影片剪辑的引用,然后使用 mc 参数设置将组件添加到舞台。

这是一个使用 Button 组件的简单示例。该命令获取所选 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.componentPanelComponentInstance参数以获得更好的图片。

华泰

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文