为许多库定义分配相同的基类

时间:2011-08-26 21:32:18

标签: flash actionscript-3

所以我知道你可以在Movieclips库信息字段中为库定义分配一个基类但是如果我在库中有30个项目并且我更改了Base类,这会成为一个痛苦的屁股,这可以通过编程方式完成当我实例化库定义?欢呼声。

var new_shiz:MyItem1 = new MyItem1(); // Needs to have a generic base class of MyItem 

3 个答案:

答案 0 :(得分:1)

使用Flash CS4,您可以在库中选择多个项目并为所有项目设置基类(通过右键单击,像往常一样)。但有时你可能真的需要更高级的方法来自动化某些东西 - 然后JSFL就是你的朋友,http://www.xjsfl.com/会让你的友谊感到高兴。

答案 1 :(得分:0)

你是否正在寻找一种方法来抓住他们的超类? 如果你的库类只是一堆图形,你可以这样做:

var new_shiz:Sprite = new MyItem1() as Sprite; 

var new_shiz:MovieClip = new MyItem1() as MovieClip; 

这是你想要做的吗?

答案 2 :(得分:-3)

// SAVE THIS CODE AS:    WHATEVERNAMEYOULIKETOCALLIT.jsfl

// Now simply open flash, select the items you'd like to change the base class IN THE LIBRARY and double click the script



/**
 * ...
 * @author Bruno Pavanelli Mestre dos Magos
 */
var lib = fl.getDocumentDOM().library;
var libSelection = lib.getSelectedItems();
var length = libSelection.length;
var appendix;
var count = 0;

Validate();

function Validate()
{
    fl.outputPanel.clear();
    fl.trace(">>> Change Base Class Name\nThis will change the base class name to every\nselected item in your library.");

    if(length <= 0)
    {
        fl.trace("No objects selected in the library!");
        alert("No objects selected in the library!");
        return;
    }

    appendix = prompt("Choose a name for the base class(ex: flash.display.MovieClip)");
    if(appendix == null) 
    {
        fl.trace("Appendix selection canceled!");
        return;
    }

    Execute();
} 

function Execute()
{

    for(var itemIndex=0; itemIndex < length; itemIndex++)
    {
        var theItem = libSelection[itemIndex];
        if(theItem.linkageExportForAS)
            {
            theItem.linkageBaseClass = appendix;
            continue;
        }else{
            theItem.linkageExportForAS = true;
            var wholePackage = appendix.split('.');
            var name = wholePackage[wholePackage.length-1];
            theItem.linkageClassName = name + itemIndex.toString();
            theItem.linkageBaseClass = appendix;
        }
        count++;
    }

    fl.outputPanel.trace("Process Complete!\n" + count + " base class name(s) modified!");
}