저는 플래시와 액션 스크립트 3에 대해 매우 새롭습니다. 저는 그것에 대해 많은 것을 읽었으며, 이것 또한 객체 지향 프로그래밍에 관한 첫 번째 aprouch입니다.AS3을 올바르게 작성하고 있습니까?
지금까지 로그인 버튼으로 애플리케이션을 만들었습니다. 그러나 나는 어떤 일이 잘못되었거나 다른 일을해야 하는지를 알고 싶다. 나는 3.
주요 액션 스크립트 파일이 Client2.as 어도비 플렉스 빌더를 사용하고 있습니다 : 그것은 로그인 인터페이스 객체를로드
package
{
//import required libraries
import flash.display.Sprite;
//set project properties
[SWF(width="800", height="600", frameRate="31", backgroundColor="#C0C0C0")]
//launch main class
public class Client2 extends Sprite
{
public function Client2() { //the constructor
trace("Client launched.");
var loginGui:LoginInterface = new LoginInterface(); //load the login interface object
loginGui.init(); //initialize the login interface (load it)
addChild(loginGui); //add login gui to the display tree
}
}
}
. 그게 좋은 일인가? 나는 그것을 올바른 방향으로하고 있는가? 무슨 약
package
{
//import required libraries
import flash.display.Sprite;
//the LoginInterface class
public class LoginInterface extends Sprite
{
public function LoginInterface() //the constructor
{
trace("LoginInterface object loaded.");
}
public function init():void //initialize the login interface (load it)
{
trace("LoginInterface init method was called.");
var loginButton:CustomButton = new CustomButton(300, 300, 100, 30, 3, 18, "Login!"); //create a new custom button
addChild(loginButton); //add the custom button to the display tree
}
}
}
:
그런 다음 LoginInterface.as 클래스 파일이있어? 다른하실 말씀 있나요? >
package
{
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
public class CustomButton extends Sprite
{
public function CustomButton(xLoc:int, yLoc:int, width:int, height:int, iLabelOffset:int, fontsize:uint, label:String)
{
//create new simple button instance
var myButton:SimpleButton = new SimpleButton();
//create the look of the states
var normal:Sprite = new Sprite();
normal.graphics.lineStyle(1, 0x000000);
normal.graphics.beginFill(0x6D7B8D);
normal.graphics.drawRect(xLoc, yLoc, width, height);
//the mouseover sprite
var over:Sprite = new Sprite();
over.graphics.lineStyle(1, 0x000000);
over.graphics.beginFill(0x616D7E);
over.graphics.drawRect(xLoc, yLoc, width, height);
// assign the sprites
myButton.upState = normal;
myButton.downState = normal;
myButton.hitTestState = normal;
myButton.overState = over;
//add the button to the display tree
addChild(myButton);
//create button label
var tText:TextField = new TextField();
tText.mouseEnabled = false,
tText.x = xLoc;
tText.y = yLoc + iLabelOffset;
tText.width = width;
tText.selectable = false
var Format:TextFormat = new TextFormat();
Format.font = "Arial";
Format.color = 0x000000;
Format.size = fontsize;
Format.bold = false;
Format.align = TextFormatAlign.CENTER;
tText.defaultTextFormat = Format;
tText.text = label;
addChild(tText)
}
}
}
이에 대해 언급 할 수 있나요 - 간단한 버튼의 창조 좀 더 쉽게하려면, 나는 다음 다른 클래스 파일이라고 CustomButton.as을 만들어? 나는 내가 많은 것을 잘못하고 있다고 확신한다. 아마도 객체 지향적 인 것을 얻지 못했을 것이다. 또한 클래스 선언 다음에 "extends ..."를 사용하는 방식에 대해 나쁘다는 느낌이 들었습니다. 주로 Sprite를 항상 사용하고 있기 때문에 왜 그런지 또는 무엇이 문제인지 이해하지 못하기 때문에 (문제가 생겼습니다. 인터넷에서도 알아 낸다). 내가 확신 할 수없는 또 다른 사실은 AS3의 변수 이름 지정입니다. 실제로 xLoc 또는 iLabelOffset과 같은 이름을 사용해야합니까? 적어도 내 이름을 짓는 변수에 일관성이 없다고 생각합니까?
나는이 동물에 대한 작업을 계속하기 전에 다른 사람이 나에게 AS3 코딩을 향상시켜야한다고 확신하기 때문에 누군가가 나에게 더 나은 트랙을 제공 할 수 있기를 바랍니다.
고마워요.
프레임 속도를보고 좋은 31 신화 살아 있고 발로 차 있습니다! – spender
FR31 신화 란 무엇입니까? 나는 그것을 찾았지만 많은 사람들이 31 세를 선호하는 것으로 나타났습니다. – invertedSpear