如何将AS2代码转换为AS3? (图库图片)

时间:2013-04-16 02:06:16

标签: actionscript-3 actionscript-2

我是个新手。我按照本教程。这是网址 virtualhacker.wikispaces.com/file/view/funci%C3%B3n+para+el+bot%C3%B3n+Siguiente.pdf/156572951/funci%C3%B3n%20para%20el%20bot%C3%B3n%20Siguiente。 PDF

是图片库。

我在AS2中实现了代码,它运行得非常好。 教程

中缺少此代码
 The code to center the images

sput_mc._x=(500-233)/2;
sput_mc._y=(250-50)/2;

和if条件语句代码转到图片编号1,

if (npictures==5){ npictures=1
            }

没有上面的代码就会给你这个错误

Error opening URL 'file:/gal/Gallery/undefined'

以下是完整的AS2代码:

var npictures:Number=1
var images:Array=new Array()
images[1]="images/image_01.jpg"
images[2]="images/image_02.jpg"
images[3]="images/image_03.jpg"
images[4]="images/image_04.jpg"

// TO CENTER THE IMAGE
sput_mc._x=(500-233)/2;
sput_mc._y=(250-50)/2;

number_txt.text=npictures
sput_mc.loadMovie(images[npictures])

neut_btn.onPress=function(){
    npictures=Number(number_txt.text)
    sput_mc.loadMovie(images[npictures])
}

prev_btn.onPress=function(){
    npictures--
    number_txt.text=npictures
    sput_mc.loadMovie(images[npictures])
}

//remember the If statement to avoid the error
forw_btn.onPress=function(){
    npictures++
    if (npictures==5){ npictures=1
        }
    number_txt.text=npictures
    sput_mc.loadMovie(images[npictures])
}

可以体验flash AS3代码大师在AS3中找出代码。请帮忙!

/////////////////////////////////////////////// /////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////

谢谢你们

我在阅读 as3参考

后就做到了

http://www.actionscript.org/forums/showthread.php3?p=989392 http://www.flashandmath.com/howtos/imgload/

这是一个很好的方法吗?或者不需要toString的东西或null,addChild?

var npictures:Number=1

//the addChild null
var sput_mc:sput_mc=new sput_mc();
this.addChild(sput_mc);

var images:Array = new Array(
'pic1.jpg', 
'pic2.jpg',
'pic3.jpg',
'pic4.jpg');


sput_mc.x=130;
sput_mc.y=90;

//toString
number_txt.text=npictures.toString();
sput_mc.load(new URLRequest(images[npictures]));



neut_btn.addEventListener(MouseEvent.CLICK,onEntClick);

function onEntClick(e:MouseEvent):void 
{
    number_txt.text=npictures.toString();
    sput_mc.load(new URLRequest(images[npictures]));

}


forw_btn.addEventListener(MouseEvent.CLICK,onForwClick);

function onForwClick(e:MouseEvent):void 
{

    npictures++
    if (npictures==4){ npictures=0
        }       

}


prev_btn.addEventListener(MouseEvent.CLICK,onBacklick);
function onBackClick(e:MouseEvent):void 

{       
        //
    npictures--
    if (npictures==4){ npictures=0
        }
    // toString()   
    number_txt.text=npictures.toString();
    sput_mc.load(new URLRequest(images[npictures]));

}

2 个答案:

答案 0 :(得分:1)

您将遇到的主要区别是:

_x和_y成了x和y。

loadMovie不再存在。您必须使用Loader代替Sprite

事件侦听器在AS3中不起作用,例如,单击侦听器:

forw_btn.addEventListener(MouseEvent.CLICK, onForwardClick);

private function onForwardClick(e:MouseEvent):void
{
  //action
}

对于其他人,我必须同意评论者的意见,你必须自己尝试一下,然后就具体问题寻求帮助。

答案 1 :(得分:0)

不要问这些类型的问题......他们不会帮助其他用户。但要认真学习 - 认真,不要让其他人为你做你的工作。但是在这里,接受它 -

var npictures:Number=1
var images:Array=new Array()
images[1]="images/image_01.jpg"
images[2]="images/image_02.jpg"
images[3]="images/image_03.jpg"
images[4]="images/image_04.jpg"

// TO CENTER THE IMAGE
sput_mc.x=(500-233)/2;
sput_mc.y=(250-50)/2;

number_txt.text=npictures
sput_mc.load(new URLRequest(images[npictures]));

neut_btn.addEventListener(MouseEvent.CLICK, soup);

function soup(e:MouseEvent):void
{
    npictures=Number(number_txt.text)
    sput_mc.load(new URLRequest(images[npictures]));
}

prev_btn.addEventListener(MouseEvent.CLICK, watevadude);

function watevadude(e:MouseEvent):void
    npictures--
    number_txt.text=npictures
    sput_mc.load(new URLRequest(images[npictures]));
}

//remember the If statement to avoid the error
forw_btn.addEventListener(MouseEvent.CLICK, hey);

function hey(e:MouseEvent):void
{
    npictures++;
    if (npictures==5){ npictures=1;
        }
    number_txt.text=npictures;
    sput_mc.load(new URLRequest(images[npictures]));
}

不要问这些问题......我是唯一一个愚蠢的人,所以不要指望其他人这样做。你为什么不支付别人去做什么呢?或学习AS3 !!!