文件 Class 中有错误?
Error in File Class?
我在名称阶段有一个按钮 "butdin" 并将他添加为 class : 我想在您按下文件中的菜单按钮时显示为什么按钮不起作用。 .
package {
import flash.display.MovieClip;
import flash.system.fscommand;
import flash.media.SoundMixer;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import fl.display.ProLoader;
import flash.system.fscommand;
import fl.video.FLVPlayback;
import flash.display.StageAlign;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.controls.List;
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;
import flash.display.SimpleButton;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import fl.controls.Button;
import flash.display.SimpleButton;
public class butdin extends SimpleButton {
butdin.addEventListener(MouseEvent.CLICK, sayit);
public function sayit(e : MouseEvent) : void {
var list : List = new List();
list.setSize(361, 291);
list.move(421, 254);
var i : uint;
for (i = 1; i < 8; i++) {
list.addItem({label:"Track " + i});
}
list.addItem({label:"Track 1"});
list.addItem({label:"Track 2"});
list.addItem({label:"Track 3"});
list.addItem({label:"Track 4"});
list.addItem({label:"Track 5"});
list.addItem({label:"Track 6"});
list.addItem({label:"Track 7"});
addChild(list);
}
list.addEventListener(Event.CHANGE, itemClick);
public function itemClick() {
status_txt.text = "You selected: " + event.target.selectedItem.label;
}
}
}
您共享的代码将无法正常工作。因为您创建了按钮 class wrongly.You 正在尝试添加列表并尝试访问文本字段。不可能 anyway.Instead 您可以添加文档 class 。
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
var list:List;
public function Main() {
butdin.addEventListener (MouseEvent.CLICK, sayit);
}
private function sayit (e:MouseEvent):void
{
list = new List();
list.setSize (361,291);
list.move (421, 254);
//var i:uint;
//for (i=1; i<8; i++)
//{
//list.addItem ( { label: "Track " + i } );
//}
list.addItem ( { label: "Track 1" } );//Opens swf file 1.swf in next frame on stage
list.addItem ( { label: "Track 2" } );//Opens swf file 2.swf in next frame on stage
list.addItem ( { label: "Track 3" } );
list.addItem ( { label: "Track 4" } );
list.addItem ( { label: "Track 5" } );
list.addItem ( { label: "Track 6" } );
list.addItem ( { label: "Track 7" } );
addChild (list);
list.addEventListener (Event.CHANGE, itemClick);
}
private function itemClick ()
{
status_txt.text = "You selected: " + event.target.selectedItem.label;
}
}
}
确保导入所有必要的包并且按钮和文本字段具有实例名称
尽量简单,你不需要 butdin
class,你可以直接在舞台中插入你的列表,然后创建你的文档 class项目:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Main extends MovieClip {
public function Main() {
butdin.addEventListener(MouseEvent.CLICK, btn_on_Press);
list.addEventListener(Event.CHANGE, list_on_Change);
}
private function btn_on_Press(e:MouseEvent): void {
for (var i:int = 1; i < 8; i++){
list.addItem ({ label: 'Track ' + i });
}
}
private function list_on_Change(e:Event): void {
trace('You selected : ' + e.target.selectedItem.label);
}
}
}
希望能帮到你。
我在名称阶段有一个按钮 "butdin" 并将他添加为 class : 我想在您按下文件中的菜单按钮时显示为什么按钮不起作用。 .
package {
import flash.display.MovieClip;
import flash.system.fscommand;
import flash.media.SoundMixer;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import fl.display.ProLoader;
import flash.system.fscommand;
import fl.video.FLVPlayback;
import flash.display.StageAlign;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.controls.List;
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;
import flash.display.SimpleButton;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import fl.controls.Button;
import flash.display.SimpleButton;
public class butdin extends SimpleButton {
butdin.addEventListener(MouseEvent.CLICK, sayit);
public function sayit(e : MouseEvent) : void {
var list : List = new List();
list.setSize(361, 291);
list.move(421, 254);
var i : uint;
for (i = 1; i < 8; i++) {
list.addItem({label:"Track " + i});
}
list.addItem({label:"Track 1"});
list.addItem({label:"Track 2"});
list.addItem({label:"Track 3"});
list.addItem({label:"Track 4"});
list.addItem({label:"Track 5"});
list.addItem({label:"Track 6"});
list.addItem({label:"Track 7"});
addChild(list);
}
list.addEventListener(Event.CHANGE, itemClick);
public function itemClick() {
status_txt.text = "You selected: " + event.target.selectedItem.label;
}
}
}
您共享的代码将无法正常工作。因为您创建了按钮 class wrongly.You 正在尝试添加列表并尝试访问文本字段。不可能 anyway.Instead 您可以添加文档 class 。
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
var list:List;
public function Main() {
butdin.addEventListener (MouseEvent.CLICK, sayit);
}
private function sayit (e:MouseEvent):void
{
list = new List();
list.setSize (361,291);
list.move (421, 254);
//var i:uint;
//for (i=1; i<8; i++)
//{
//list.addItem ( { label: "Track " + i } );
//}
list.addItem ( { label: "Track 1" } );//Opens swf file 1.swf in next frame on stage
list.addItem ( { label: "Track 2" } );//Opens swf file 2.swf in next frame on stage
list.addItem ( { label: "Track 3" } );
list.addItem ( { label: "Track 4" } );
list.addItem ( { label: "Track 5" } );
list.addItem ( { label: "Track 6" } );
list.addItem ( { label: "Track 7" } );
addChild (list);
list.addEventListener (Event.CHANGE, itemClick);
}
private function itemClick ()
{
status_txt.text = "You selected: " + event.target.selectedItem.label;
}
}
}
确保导入所有必要的包并且按钮和文本字段具有实例名称
尽量简单,你不需要 butdin
class,你可以直接在舞台中插入你的列表,然后创建你的文档 class项目:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Main extends MovieClip {
public function Main() {
butdin.addEventListener(MouseEvent.CLICK, btn_on_Press);
list.addEventListener(Event.CHANGE, list_on_Change);
}
private function btn_on_Press(e:MouseEvent): void {
for (var i:int = 1; i < 8; i++){
list.addItem ({ label: 'Track ' + i });
}
}
private function list_on_Change(e:Event): void {
trace('You selected : ' + e.target.selectedItem.label);
}
}
}
希望能帮到你。