2013-04-16 79 views
-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代碼轉換爲AS3? (圖庫圖片)

是圖片庫。

我在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]) 
} 

體驗閃存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])); 

} 
+0

你試過了嗎?如果是這樣,你卡在哪裏?如果不是的話,當你遇到問題時,一定要回去再回來。 – Marty

+0

這不是一個「免費翻譯」網站。請自己嘗試。如果你遇到困難,請回來,我們會盡力幫助你。 – Ihsan

+0

不要求代碼翻譯;學習as3。 – 2013-04-27 00:47:41

回答

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!

+0

謝謝你們,你們能檢查一下我做的代碼是否有些不同。 – gunt

+0

@gunt你的代碼很好。如果變量是一個數字或整數,則需要使用toString(),否則你不要 – 2013-04-20 16:41:00

+0

謝謝,現在我知道了! – gunt

1

,你會遇到的主要區別是:

_x和_y成爲x和y。

loadMovie不存在了。您必須使用Loader而不是Sprite

的事件監聽器不工作在AS3這種方式,例如,點擊收聽:

forw_btn.addEventListener(MouseEvent.CLICK, onForwardClick); 

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

至於其他,我必須與評論者同意,你必須給它一個嘗試自己,然後尋求特定點的幫助。