-4

我是一个flash新手。我按照本教程进行操作。这是网址 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]));

}
4

2 回答 2

1

您将遇到的主要区别是:

_x 和 _y 变成了 x 和 y。

loadMovie不再存在。您必须使用 aLoader而不是 a Sprite

事件监听器在 AS3 中不是这样工作的,例如,点击监听器:

forw_btn.addEventListener(MouseEvent.CLICK, onForwardClick);

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

其余的,我必须同意评论者的观点,你必须自己尝试一下,然后就具体问题寻求帮助。

于 2013-04-16T08:56:40.243 回答
0

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

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!

于 2013-04-20T00:24:06.203 回答