2011-09-26 106 views
0

我正在玩一个画廊。我想添加更多的功能。鼠标点击处理在As3.0画廊

这里的初始代码:

import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.display.MovieClip; 

function doSMTH(luka) { 
var catNum:Number = luka; 

stop(); 
goBack.addEventListener(MouseEvent.CLICK, goBacke); 
    function goBacke(e:MouseEvent):void{ 
     gotoAndStop(1); 
     stage.removeChild(thumbnail_group); 
} 


// Tweener 
// http://code.google.com/p/tweener/ 
import caurina.transitions.*; 

var filename_list = new Array(); 
var url_list = new Array(); 
var url_target_list:Array = new Array(); 
var title_list = new Array(); 
var description_list = new Array(); 

var i:Number; 
var tn:Number = 0; 
var tween_duration:Number = 0.4; 
var move_x:Number = 200; 
var move_y:Number = -300; 

//var fm_tween:Tween; 
var total:Number; 
var flashmo_xml:XML = new XML(); 
var folder:String = "photos/"; 
var xml_loader:URLLoader = new URLLoader(); 
xml_loader.load(new URLRequest("gallery.xml")); 
xml_loader.addEventListener(Event.COMPLETE, create_thumbnail); 

var thumbnail_group:MovieClip = new MovieClip(); 
stage.addChild(thumbnail_group); 

thumbnail_group.x = tn_group.x; 
var default_y:Number = thumbnail_group.y = tn_group.y; 

tn_group.visible = false; 
url_button.visible = false; 
tn_title.text = ""; 
tn_desc.text = ""; 
tn_url.text = ""; 
tn_url_target.text = ""; 

function create_thumbnail(e:Event):void 
{ 
    flashmo_xml = XML(e.target.data); 
    total = flashmo_xml.category[catNum].thumbnail.length(); 

    for(i = 0; i < total; i++) 
    { 
     filename_list.push(flashmo_xml.category[catNum].thumbnail[i][email protected]()); 
     url_list.push(flashmo_xml.category[catNum].thumbnail[i][email protected]()); 
     url_target_list.push(flashmo_xml.category[catNum].thumbnail[i][email protected]()); 
     title_list.push(flashmo_xml.category[catNum].thumbnail[i][email protected]()); 
     description_list.push(flashmo_xml.category[catNum].thumbnail[i][email protected]()); 
    } 
    load_tn(); 
} 

function load_tn():void 
{ 
    var pic_request:URLRequest = new URLRequest(folder + filename_list[tn]); 
    var pic_loader:Loader = new Loader(); 

    pic_loader.load(pic_request); 
    pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_loaded); 
    tn++; 
} 

function on_loaded(e:Event):void 
{ 
    if(tn < total) 
    { 
     load_tn(); 
     tn_desc.text = "Loading " + tn + " of " + total + " photos"; 
    } 
    else 
    { 
     tn_title.text = title_list[0]; 
     tn_desc.text = description_list[0]; 
     tn_url.text = url_list[0]; 
     tn_url_target.text = url_target_list[0]; 

     var mc:MovieClip = MovieClip(thumbnail_group.getChildAt(total-2)); 
     mc.addEventListener(MouseEvent.CLICK, go_out); 

     Tweener.addTween(mc, { rotation: 0, time: tween_duration, transition: "easeOut" }); 
     url_button.visible = true; 
     url_button.addEventListener(MouseEvent.CLICK, goto_URL); 
    } 

    var flashmo_bm:Bitmap = new Bitmap(); 
    var flashmo_mc:MovieClip = new MovieClip(); 

    flashmo_bm = Bitmap(e.target.content); 
    flashmo_bm.x = - flashmo_bm.width * 0.5; 
    flashmo_bm.y = - flashmo_bm.height * 0.5; 
    flashmo_bm.smoothing = true; 

    var bg_width = flashmo_bm.width + 16; 
    var bg_height = flashmo_bm.height + 16; 

    flashmo_mc.addChild(flashmo_bm); 
    flashmo_mc.graphics.lineStyle(1, 0x999999); 
    flashmo_mc.graphics.beginFill(0xFFFFFF); 
    flashmo_mc.graphics.drawRect(- bg_width * 0.5, - bg_height * 0.5, bg_width, bg_height); 
    flashmo_mc.graphics.endFill(); 
    flashmo_mc.x = move_x; 
    flashmo_mc.y = move_y; 
    flashmo_mc.rotation = 45; 
    flashmo_mc.name = "flashmo_" + thumbnail_group.numChildren; 

    Tweener.addTween(flashmo_mc, { x: Math.random() * 20 - 10, y: Math.random() * 20 - 10, 
         rotation: Math.random() * 20 - 10, 
         time: tween_duration * 2, transition: "easeOut" }); 

    thumbnail_group.addChildAt(flashmo_mc, 0); 
} 


function go_out(e:MouseEvent):void 
{ 

    var mc:MovieClip = MovieClip(e.target); 
    //var imgFwd:MovieClip = MovieClip(e.target); 
    mc.removeEventListener(MouseEvent.CLICK, go_out); 
    //imgFwd.removeEventListener(MouseEvent.CLICK, go_out); 
    Tweener.addTween(mc, { x: 220, y: -180, rotation: 45, time: tween_duration, 
         transition: "easeInQuart", onComplete: go_in }); 
} 

function go_in():void 
{ 
    var mc:MovieClip = MovieClip(thumbnail_group.getChildAt(total-1)); 
    var mc2:MovieClip = MovieClip(thumbnail_group.getChildAt(total-2)); 

    var s_no:Number = parseInt(mc.name.slice(8,10)) + 1; 
    if(s_no == total) s_no = 0; 

    Tweener.addTween(mc, { x: Math.random() * 20 - 10, y: Math.random() * 20 - 10, 
          rotation: Math.random() * 20 - 10, time: tween_duration, 
          transition: "easeOut", onComplete: add_click }); 
    Tweener.addTween(mc2, { rotation: 0, time: tween_duration, transition: "easeOut" }); 

    thumbnail_group.addChildAt(mc, 0); 
    tn_title.text = title_list[s_no]; 
    tn_desc.text = description_list[s_no]; 
    tn_url.text = url_list[s_no]; 
    tn_url_target.text = url_target_list[s_no]; 
} 

function add_click():void 
{ 
    var mc:MovieClip = MovieClip(thumbnail_group.getChildAt(total-1)); 
    mc.addEventListener(MouseEvent.CLICK, go_out); 
} 

function goto_URL(me:MouseEvent) 
{ 
    navigateToURL(new URLRequest(tn_url.text), tn_url_target.text); 
} 

link_to_205.addEventListener(MouseEvent.CLICK, goto_205); 

function goto_205(me:MouseEvent) 
{ 
    navigateToURL(new URLRequest(""), "_parent"); 
} 


tn_url_target.visible = false; 
tn_title.visible = false; 
tn_desc.visible = false; 
url_button.visible = false; 
tn_url.visible = false; 
link_to_205.visible = false; 

} 

我添加了两个按钮进行导航。

  1. goFWD,将有一个代码imgFwd.addEventListener(MouseEvent.CLICK, go_out);

但通过将此事件的按钮,按钮本身不补间,现在的MC:影片剪辑。

我不知道它为什么这样做?也许有任何想法?

我想,如果在AS3.0中有这样的事情 - 点击这个按钮会让AS认为mc:MovieClip被点击了?有什么那样的吗?

任何想法如何使它前进的一个按钮...提前

谢谢!

+0

你应该把你的两个问题分成两个不同的帖子。 – Kodiak

回答

1

单击goFWD按钮时应该怎样缓存?从快速的样子,我想你想补间thumbnail_group。是这样吗?

在您的MouseEvent.CLICK处理程序go_out中,您使用e.target转换当前目标(被点击的物件)。如果您要定位的thumbnail_group MC,然后只需更改代码,如下所示:

function go_out(e:MouseEvent):void 
{ 

    var mc:MovieClip = MovieClip(e.target); 
    mc.removeEventListener(MouseEvent.CLICK, go_out); 
    Tweener.addTween(thumbnail_group.getChildAt(total-1), { x: 220, y: -180, rotation: 45, time: tween_duration, 
         transition: "easeInQuart", onComplete: go_in }); 
} 

如果这是你正在寻找没有的内容,然后请澄清,我会尽力帮助你。

+0

当我写道,整个持有人,图像滑动,并在一个图像insed ..我怎么能实现thumbnai_holder e.target? – mrGott

+0

而不是thumbnail_holder我写了thumbnail_holder.getChildAt(total-1)<---它工作,但该按钮只工作一次,但点击thumbnail_holder时,它工作正常。我的按钮有什么问题? – mrGott