AS2 到 AS3 转换错误

Posted

技术标签:

【中文标题】AS2 到 AS3 转换错误【英文标题】:AS2 to AS3 conversion errors 【发布时间】:2018-04-19 13:25:25 【问题描述】:

我已将 ActionScript 2 用于 Flash 文件,但由于任何浏览器都不支持 ActionScript 2,我需要将我的 ActionScript 2 代码更改为 ActionScript 3。

当我尝试使用 Adob​​e Animate 进行转换时,它开始在使用预加载器、初始设置、垂直/水平对齐等进行图像加载时出现一些错误。

代码和错误信息如下:

//Controls Default
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
controls.zo.useHandCursor = false;
controls.zi.useHandCursor = false;
controls.br.useHandCursor = false;
controls.bl.useHandCursor = false;
controls.bu.useHandCursor = false;
controls.bd.useHandCursor = false;
controls.bres.useHandCursor = false;
resized_ = false;
cursor._visible = panWithinBoundary ? false : true;
//Image loading with preloader (if the settings made to load the image dynamically)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (image ne undefined and image ne "" and image ne null) 
    //If image path specified:
    controls._visible = false;
    mcl = new MovieClipLoader();
    tempMc = content_clip.inner_clip.ImageHolder.Content.createEmptyMovieClip("temp", 1);
    mcl.loadClip(image, tempMc);
    mcl.onLoadStart = function() 
        //Image loading progress
        loader.start_(tempMc);
    ;
    mcl.onLoadInit = function(mc) 
        //After loading the image:
        if (imageSmoothing and image.substr(image.lastIndexOf(".")+1) ne "swf") 
            //If imageSmoothing is set 'true' and the content is not swf, we need to capture the bitmap data
            //for better look:If imageSmoothing is set 'false' or the content is not an image (but swf), 
            //we should show the content 'as is' without bitmap capture.
            myBmp = new flash.display.BitmapData(mc._width, mc._height, true, 0x00CCCCCC);
            myBmp.draw(mc);
            removeMovieClip(mc);
            content_clip.inner_clip.ImageHolder.Content.attachBitmap(myBmp, 0, "auto", true);
        
        loader.unloadMovie();
        bgShade.unloadMovie();
        init();
        run();
    ;
 else 
    //If image path not specified, then assuming image is placed directly to the library:
    loader.unloadMovie();
    bgShade.unloadMovie();
    init();
    run();

//Initial settings
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function init() 
    recent = 0;
    posx = posy=0;
    canvasSize();
    iw = cW;
    ih = cH;
    mask_._width = hit._width=iw;
    mask_._height = hit._height=ih;
    cr_width = iw;
    cr_height = ih;
    ease = ease<1 ? 1 : ease;
    zoomFactor = zoomFactor<.3 ? .3 : zoomFactor;
    panSpeed = panSpeed<1 ? 1 : panSpeed;
    mSP = 1;
    mPX=_xmouse, mPY=_ymouse;
    //Aligning Control box+++++++++++++++++++++++++++++++++++++++++++++
    //Vertical Align
    controls._visible = true;
    if (controlBoxVAlign.toLowerCase() eq "top") 
        controls._y = controlBoxSpace;
     else if (controlBoxVAlign.toLowerCase() eq "middle" or controlBoxVAlign.toLowerCase() eq "center" or controlBoxVAlign.toLowerCase() eq "centre") 
        controls._y = (ih/2)-(controls._height/2);
     else 
        controls._y = ih-controls._height-controlBoxSpace;
    
    //Horizontal Align
    if (controlBoxHAlign.toLowerCase() eq "left") 
        controls._x = controlBoxSpace;
     else if (controlBoxHAlign.toLowerCase() eq "middle" or controlBoxHAlign.toLowerCase() eq "center" or controlBoxHAlign.toLowerCase() eq "centre") 
        controls._x = (iw/2)-(controls._width/2);
     else 
        controls._x = iw-controls._width-controlBoxSpace;
    
    //Initial Zoom level detection. By default, the image gets scaled to the variable value "sc" to fit it within stage atleast to one side
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    sc = (ih/content_clip.inner_clip.ImageHolder._height)*100;
    if (!zoomOutToExtreme) 
        if (content_clip.inner_clip.ImageHolder._width*(sc/100)<iw) 
            sc = (iw/content_clip.inner_clip.ImageHolder._width)*100;
        
     else 
        if (content_clip.inner_clip.ImageHolder._width*(sc/100)>iw) 
            sc = (iw/content_clip.inner_clip.ImageHolder._width)*100;
        
    

错误信息是:

Scene 1, Layer 'Actions', Frame 10, Line 14, Column 11  1084: Syntax error: expecting rightparen before ne.
Scene 1, Layer 'Actions', Frame 10, Line 26, Column 22  1084: Syntax error: expecting rightparen before and.
Scene 1, Layer 'Actions', Frame 10, Line 26, Column 63  1084: Syntax error: expecting semicolon before rightparen.
Scene 1, Layer 'Actions', Frame 10, Line 67, Column 37  1084: Syntax error: expecting rightparen before eq.
Scene 1, Layer 'Actions', Frame 10, Line 69, Column 44  1084: Syntax error: expecting rightparen before eq.
Scene 1, Layer 'Actions', Frame 10, Line 69, Column 93  1008: Attribute is invalid.
Scene 1, Layer 'Actions', Frame 10, Line 69, Column 102 1084: Syntax error: expecting rightbrace before or.
Scene 1, Layer 'Actions', Frame 10, Line 71, Column 4   1083: Syntax error: else is unexpected.

想知道,如何解决以上这些错误?

【问题讨论】:

我的回答是否修复了您显示的 8 个错误?如果太多而无法手动修复,请使用单词搜索(查找/替换工具)快速替换这些属性(neeq 等)。 【参考方案1】:

您需要研究并在代码中有错误的部分使用AS3 Operators

例如,您的代码似乎映射到以下内容:

您的ne 相当于AS3 运算符:!=(请参阅:Not Equal)。

您的eq 相当于AS3 运算符:==(请参阅:EQuality)。

您的and 相当于AS3 运算符:&amp;&amp;(请参阅:AND)。

您的or 相当于AS3 运算符:||(请参阅:OR)。

示例 #1:(AS2 代码):

if (image ne undefined and image ne "" and image ne null)

真的应该是(AS3):

if (image != undefined && image != "" && image != null)

示例 #2:(AS2 代码):

else if (controlBoxVAlign.toLowerCase() eq "middle" or controlBoxVAlign.toLowerCase() eq "center" or controlBoxVAlign.toLowerCase() eq "centre") 

真的应该是(AS3):

else if (controlBoxVAlign.toLowerCase() == "middle" || controlBoxVAlign.toLowerCase() == "center" ||controlBoxVAlign.toLowerCase() == "centre") 

【讨论】:

以上是关于AS2 到 AS3 转换错误的主要内容,如果未能解决你的问题,请参考以下文章

在 AS3 中动态加载 AS2 文件 - 如何判断文件是不是为 AS2

将动作脚本 2 转换为动作脚本 3

告诉目标代码(转换为 as3)

将应用程序从 AS2 迁移到 AS3 的优缺点是啥?

将应用程序从AS2迁移到AS3有哪些优缺点?

将 AS2 SWF 加载到 AS3 SWF 中并在 URL 中传递变量