0

我是 AS3 的新手,我发现自己需要扩展一个 fla。那是由第 3 方写的。目标是访问 flashvars,但对于我的生活来说,它无法正常工作......已经学习了好几天......

我正在使用的 fla 是具有 2 帧的时间轴上的代码。影片剪辑运行到第 2 帧并停止。

在第 2 帧上,我需要使用 flashvar。

我已经构建了一个简单的示例,它将在第二帧上填充一个文本框,效果很好。

第一帧

var my_var:String = new String();
my_var = root.loaderInfo.parameters.uploadId;

帧 2

my_txt.text = my_var;
stop();

但是,当我在第 3 方 fla 上使用相同的方法时,我得到 NULL 输出。我也没有使用任何 TLF 文本(我认为)。

我不明白为什么它在一种情况下有效,而在另一种情况下无效。我认为这可能与与周围代码的冲突有关,但我对 AS 的了解还不够,无法追踪它。对此的任何帮助将不胜感激。

第一帧

import net.bizmodules.uvg.loading;

stop();

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.showDefaultContextMenu = false;
stage.quality = StageQuality.BEST;

function RandomValue()
{
    var d = new Date();
    return String(d.getDate()) + String(d.getHours()) + String(d.getMinutes()) + String(d.getSeconds());
}
var my_var:String;
my_var = root.loaderInfo.parameters.uploadId;
var userId;
var albums:Object;
var resource:Object;
var strUploadPage:String;
if (root.loaderInfo.parameters.uploadPage != undefined)
    strUploadPage = root.loaderInfo.parameters.uploadPage;
else
    strUploadPage = "http://localhost/dnn450/desktopmodules/ultramediagallery/flashuploadpage.aspx?PortalId=0&ModuleId=455";

if (strUploadPage.indexOf("?") > 0)
    strUploadPage += "&";
else
    strUploadPage += "?";

strUploadPage += "action=loadAlbums&seed=" + RandomValue();
trace(strUploadPage);

var myLoading:MovieClip = new loading();
myLoading.x = (stage.stageWidth - myLoading.width) / 2;
myLoading.y = (stage.stageHeight - myLoading.height) / 2;
addChild(myLoading);

var myRequest:URLRequest = new URLRequest(strUploadPage); 
var myLoader:URLLoader = new URLLoader(myRequest); 
myLoader.addEventListener(Event.COMPLETE, xmlLoaded); 

function xmlLoaded(evtObj:Event) 
{ 
    myLoader.removeEventListener(Event.COMPLETE, xmlLoaded);
    try
    {

        var xDoc:XMLDocument = new XMLDocument();
        xDoc.ignoreWhite = true;
        var xml:XML = XML(myLoader.data);
        xDoc.parseXML(xml.toXMLString());
        userId=xDoc.firstChild.attributes.userId;

        if (userId < 0)
        {
            removeChild(myLoading);
            txtError.text = "Please ensure you are logged in";
            return;
        }

        if(xDoc.firstChild.childNodes.length > 0)
        {
            albums = xDoc.firstChild.childNodes[0].childNodes;
            resource = xDoc.firstChild.childNodes[1].attributes;
        }
        else
        {
            removeChild(myLoading);
            txtError.text = xDoc.firstChild.attributes.error;
            return;
        }
        play();
    }
    catch(e:Error)
    {
        removeChild(myLoading);
        txtError.text = e + "\n\nPlease check your Event Viewer to find out detailed error message and contact service@bizmodules.net";
    }
}

帧 2

import net.bizmodules.upg.Alert;

stop();
removeChild(myLoading);

initialize();

function initialize()
{
    Alert.init(stage);

    upload.addVar("userId",userId);


    lstAlbums.dropdown.rowHeight = 24; 

    loadAlbums(0, albums);

    var my_so:SharedObject = SharedObject.getLocal("UPGUpload");
    var lastAlbum = my_so.data.lastAlbum * 1;
    var foundLastAlbum = false;
    if (lastAlbum > 0)
    {
        for (var i:int = 0; i< lstAlbums.length; i++)
        {
            if (lstAlbums.getItemAt(i).data == lastAlbum)
            {
                trace("find previous album");
                foundLastAlbum = true;
                lstAlbums.selectedIndex = i;
                break;
            }
        }
    }

    if (!foundLastAlbum)
    {
        lstAlbums.selectedIndex = lstAlbums.length - 1;
    }
    albums_change(null);

    lstAlbums.addEventListener("change", albums_change);

    lstAlbums.setStyle("backgroundColor", 0x504C4B);
    lstAlbums.dropdown.setStyle("backgroundColor", 0x504C4B);
    lstAlbums.setStyle("themeColor", 0x1F90AE);
    lstAlbums.setStyle("color", 0xC4C0BF); 
    lstAlbums.setStyle("textSelectedColor", 0xC4C0BF); 
    lstAlbums.setStyle("textRollOverColor", 0xC4C0BF); 
    lstAlbums.setStyle("alternatingRowColors", [0x504C4B, 0x504C4B]);
    lstAlbums.setStyle("borderStyle", 'none'); 

}

my_txt.text = "hello" + " " + my_var;


function loadAlbums(level:int, xml:Object)
{

    var prefix = "                                                     ".substring(0, level * 4);;

    for (var i:int = 0;i<xml.length;i++)
    {
        var itemValue = xml[i].attributes.itemid;
        if (xml[i].childNodes.length > 0)
            itemValue *= -1;

        lstAlbums.addItem({data: itemValue, label: prefix + xml[i].attributes.name});
        if (xml[i].childNodes.length > 0)
        {
            loadAlbums(level + 1, xml[i].childNodes);
        }
    }
}

function albums_change(e)
{   
    var albumId = lstAlbums.getItemAt(lstAlbums.selectedIndex).data;
    upload.set_albumId(albumId);
    if (albumId > 0)
    {
        var my_so:SharedObject = SharedObject.getLocal("UPGUpload");
        my_so.data.lastAlbum = albumId;
    }
    else
    {       
        Alert.show("The album you choosed is invalid", null, 0xEAEAEA, 0x000000);
    }
}
4

1 回答 1

0
private var flashVarObj:Object = new Object;
flashVarObj=LoaderInfo(this.loaderInfo).parameters;
var my_var:String = new String();
my_var = flashVarObj.uploadIdd;
于 2012-04-09T08:25:51.713 回答