1、请用Object对象构建一个学生对象student,要求具有姓名,年龄和性别的属性
2、请运行如下代码显示结果是?
var str:String=””;
(1)for(var prop:String in student){
str = str +"\n"+prop+":"+student[prop].toString();
}
trace(str);
(2) for each(var value:* in student){
str = str +"\n"+value.toString();}
trace(str);
3、设置一个计算器
如图:
4、请建立一个用户登入界面,要求输入用户名和密码。如果输入用户名和密码分别是“张三”和“12345”,则显示一个欢迎窗口;否则清空登入信息
我一个都不会。。。帮朋友问的,我又不学这个,你帮个忙撒。。。把答案都贴出来
1:
var student:Object = new Object;
student.name = "zhangsan";
student.age = 20;
student.sex = "男";
2:
(1):sex:男;
age:20;
name:zhangsan;
(2):男
20
zhangsan
3:以前写的一个计算器 给你参考一下;
计算器逻辑代码:
package com.calculator.ui
{
import com.calculator.event.ButtonChangeEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import mx.containers.VBox;
import mx.controls.Button;
import mx.controls.TextInput;
import mx.events.FlexEvent;
public class CalculatorMainBox extends VBox
{
private var txtIn:TextInput;
private var btn:Button;
public function CalculatorMainBox()
{
addEventListener(FlexEvent.INITIALIZE,init);
setStyle("verticalGap",5);
setStyle("top",10);
addEventListener(ButtonChangeEvent.GET_BUTTON_LABEL,getButtonValue);
addEventListener(ButtonChangeEvent.GET_BUTTON_EQUAL,getTextValue)
}
private function init(event:FlexEvent):void
{
paint();
}
private function getTextValue(event:ButtonChangeEvent):void
{
calculate();
}
private var valueStr:String;
private var value:String;
private var initialValue:String="0";
[Bindable]private var initiaLValue_1:String;
private var lastValue:String;
private function getButtonValue(event:ButtonChangeEvent):void
{
if(isNaN(parseFloat(initialValue.charAt(initialValue.length-1))))
{
initiaLValue_1 = txtIn.text;
txtIn.text = "0";
initialValue = "0";
}
if(!(isNaN(parseFloat(event.getButtonVaule))))
{
if(txtIn.text=="0")
txtIn.text = "";
txtIn.text+=event.getButtonVaule;
}
else
{
if(isNaN(parseFloat(txtIn.text.charAt(txtIn.text.length))))
{
if(txtIn.text.indexOf(".")==-1)
{
if(event.getButtonVaule =="."||!(isNaN(parseFloat(event.getButtonVaule))))
{
if(txtIn.text.charAt(txtIn.text.length)!=".")
txtIn.text+=".";
}
}
}
if(event.getButtonVaule == "+/-")
{
if(parseFloat(txtIn.text)>0)
{
txtIn.text = "-"+txtIn.text;
}
else if(parseFloat(txtIn.text)<0)
{
txtIn.text = txtIn.text.substr(1,txtIn.text.length-1);
}
}
if(event.getButtonVaule=="+"||event.getButtonVaule=="-"||event.getButtonVaule=="*"||event.getButtonVaule=="/")
{
value = event.getButtonVaule;
getInitialValue(event.getButtonVaule);
}
}
valueStr+=event.getButtonVaule;
}
private function clean(event:MouseEvent):void
{
txtIn.text = "0";
initialValue = "0";
initiaLValue_1 = "0";
}
[Bindable]private var result:Number;
private function getInitialValue(str:String):void
{
initialValue = txtIn.text+str;
//calculate();
}
private function calculate():void
{
if(value=="+")
txtIn.text = (parseFloat(initiaLValue_1)+parseFloat(txtIn.text))+"";
if(value=="-")
txtIn.text = (parseFloat(initiaLValue_1)-parseFloat(txtIn.text))+"";
if(value=="*")
txtIn.text = (parseFloat(initiaLValue_1)*parseFloat(txtIn.text))+"";
if(value=="/")
txtIn.text = (parseFloat(initiaLValue_1)/parseFloat(txtIn.text))+"";
}
private function paint():void
{
txtIn = new TextInput();
txtIn.width = 235;
txtIn.text = "0";
txtIn.setStyle("textAlign","right");
txtIn.setStyle("FontWeight","NORMAL");
txtIn.restrict = "0-9";
addChild(txtIn);
btn = new Button;
btn.label = "C";
btn.setStyle("color","red");
btn.width = 235;
btn.addEventListener(MouseEvent.CLICK,clean);
addChild(btn);
var key:CalculatorKey = new CalculatorKey;
addChild(key);
}
}
}
计算器页面布局代码:
package com.calculator.ui
{
import com.calculator.event.ButtonChangeEvent;
import flash.events.MouseEvent;
import mx.containers.HBox;
import mx.containers.Tile;
import mx.controls.Button;
import mx.events.FlexEvent;
public class CalculatorKey extends HBox
{
private var butTile:Tile;
private var keyArr:Array = new Array(7,8,9,"/",4,5,6,"*",1,2,3,"-",0,"+/-",".","+");
public function CalculatorKey()
{
addEventListener(FlexEvent.INITIALIZE,init);
setStyle("horizontalGap",2);
}
private function init(event:FlexEvent):void
{
paint();
}
private function getLabel(event:MouseEvent):void
{
var evt:ButtonChangeEvent = new ButtonChangeEvent(ButtonChangeEvent.GET_BUTTON_LABEL);
evt.getButtonVaule = (event.target as Button).label;
this.dispatchEvent(evt);
}
private function paint():void
{
butTile = new Tile;
butTile.setStyle("horizontalGap",1);
butTile.setStyle("verticalGap",8);
for(var i:int=0;i<keyArr.length;i++)
{
var btn:Button = new Button;
btn.label = keyArr[i].toString();
if(keyArr[i] is Number)
{
btn.setStyle("color","blue");
}
else
{
btn.setStyle("color","red");
}
btn.addEventListener(MouseEvent.CLICK,getLabel);
butTile.addChild(btn);
}
addChild(butTile);
var btn_1:Button = new Button;
btn_1.addEventListener(MouseEvent.CLICK,getMyEQ);
btn_1.setStyle("color","red");
btn_1.label = "=";
btn_1.height = 113;
addChild(btn_1);
}
private function getMyEQ(event:MouseEvent):void
{
this.dispatchEvent(new ButtonChangeEvent(ButtonChangeEvent.GET_BUTTON_EQUAL));
}
}
}
计算器事件代码:
package com.calculator.event
{
import flash.events.Event;
public class ButtonChangeEvent extends Event
{
public static const GET_BUTTON_LABEL:String = "get_button_label";
public static const GET_BUTTON_EQUAL:String ="get_button_equal";
public var getButtonVaule:String;
public function ButtonChangeEvent(type:String,bubbles:Boolean = true,user_capture:Boolean = false)
{
super(type,bubbles,user_capture);
}
}
}
计算器外部的panel容器代码:
package com.calculator.ui
{
import mx.containers.Panel;
public class CalculatorPanel extends Panel
{
public function CalculatorPanel()
{
super();
this.title = "计算器";
setStyle("paddingLeft",10);
setStyle("paddingRight",10);
setStyle("paddingTop",10);
setStyle("paddingBottom",10);
}
}
}
4:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" fontSize="12">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
protected function button1_clickHandler(event:MouseEvent):void
{
if(user_name.text=="张三"&&user_pass.text=="12345")
{
Alert.show("欢迎登录","提示:");
}else{
clean();
}
}
private function clean():void
{
user_name.text = "";
user_pass.text = "";
}
]]>
</mx:Script>
<mx:Panel title="登录框" width="273" height="218" horizontalAlign="center" verticalAlign="middle">
<mx:Form width="100%">
<mx:FormItem width="100%" label="账号:" horizontalAlign="center">
<mx:TextInput id="user_name"/>
</mx:FormItem>
<mx:FormItem width="100%" label="密码:" horizontalAlign="center">
<mx:TextInput id="user_pass" displayAsPassword="true"/>
</mx:FormItem>
</mx:Form>
<mx:HBox width="100%" horizontalAlign="right" paddingRight="30">
<mx:Button label="登录" click="button1_clickHandler(event)"/>
<mx:Button label="清空" click="clean()"/>
</mx:HBox>
</mx:Panel>
</mx:Canvas>
计算器图片
本回答被提问者采纳