是否有一种简单的方法可以为另一个动态加载的movieClip切换movieClip?
我有和eventListener onCLICK,当它被选中时它会启动FLVPlayback,但我还想换掉另一个movieClip立即播放/正在播放按钮。
只是一些背景知识。我正在循环并将播放按钮jpg加载到一个影片剪辑中,并将增量编号作为名称分配给播放按钮影片剪辑。单击该播放按钮播放电影,但现在我还想将播放按钮图形切换为正在播放的图形。
//ADD EVENT LISTENER TO ALL MY THUMBS_BUTTON
thumbs_button.addEventListener (MouseEvent.CLICK, playVideoThumb);
for (var i:Number = 0; i < my_total; i++) {
var playButton_url = "play_now.png";
var playButton_loader = new Loader();
playButton_loader.name = i;
playButton_loader.load (new URLRequest(root_path + playButton_url));
playButton_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, playButtonLoaded);
playButton_loader.y = (115 * i) + (135 * i) + 138;
//PUT NEW LOADED IMAGE INTO THUMBS_BUTTON
function playButtonLoaded (e:Event):void {
var my_playButton:Loader = Loader(e.target.loader);
thumbs_button.addChild (my_playButton);
}
//THIS IS WHERE I NEED TO REMOVE THE PLAY NOW AND PUT IN THE NOW PLAYING BUTTON
function playVideoThumb (e:MouseEvent):void {
var video_url = root_path + my_videos[e.target.name].@URL;
my_player.source = video_url;
var blank_butt:Number = thumbs_button.getChildByName(e.target.name).x;
thumbs_button.removeChild(thumbs_button.getChildByName(e.target.name));
}
答案 0 :(得分:1)
看看你的代码我假设你可能想要一个类似无线电按钮的功能。有几种方法可以做到这一点。一种方法是删除和添加子项,或者在下面的情况下使用visible属性:
// will contain hidden button
var hidden_button: DisplayObject = null;
// playing now button
var playingNow_button: Loader;
//ADD EVENT LISTENER TO ALL MY THUMBS_BUTTON
thumbs_button.addEventListener (MouseEvent.CLICK, playVideoThumb);
for (var i:Number = 0; i < my_total; i++) {
var playButton_url: String = "play_now.png";
var playButton_loader: Loader = new Loader();
playButton_loader.name = i;
playButton_loader.load (new URLRequest(root_path + playButton_url));
playButton_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, playButtonLoaded);
playButton_loader.y = (115 * i) + (135 * i) + 138;
}
// load playingNow graphic
playingNow_button = new Loader();
playingNow_button.load(new URLRequest(root_path + 'playing_now.png'));
playingNow_button.contentLoaderInfo.addEventListener (Event.COMPLETE, playingNowLoaded);
//PUT NEW LOADED IMAGE INTO THUMBS_BUTTON
function playButtonLoaded (e:Event):void {
var my_playButton:Loader = Loader(e.target.loader);
thumbs_button.addChild (my_playButton);
}
//ADD PLAYING_NOW BUT HIDE
function playingNowLoaded (e:Event):void {
playingNow_button.visible = false;
thumbs_button.addChild (playingNow_button);
}
//THIS IS WHERE I NEED TO REMOVE THE PLAY NOW AND PUT IN THE NOW PLAYING BUTTON
function playVideoThumb (e:MouseEvent):void {
// exit if user clicked playing Now button
if (e.target == playingNow_button) return;
// also exit if user clicked on something that is not a loader
if (!(e.target is Loader)) return;
// show hidden button (if any)
if (hidden_button != null) hidden_button.visible = true;
// assign current button to hidden_button
hidden_button = DisplayObject(e.target);
// copy location, scale and rotation
playingNow_button.transform.matrix = hidden_button.transform.matrix;
// show playingNow and hide button
playingNow_button.visible = true;
hidden_button.visible = false;
// play video
var video_url = root_path + my_videos[e.target.name].@URL;
my_player.source = video_url;
}
如果您不需要处理已加载的按钮,可以立即将Loader对象添加到thumbs_button。您不必在COMPLETE处理程序中执行此操作。