2011-09-26 3 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; 

} 

내가 탐색을위한 두 개의 버튼을 추가했습니다. 코드 imgFwd.addEventListener(MouseEvent.CLICK, go_out);

을 가지고 있지만 버튼에이 이벤트를 추가하여 것이다

  1. goFWD는 버튼 자체가 이제 엠씨 트윈을 수행하고 : 무비 클립.

    왜 그런지 모르겠습니까? 어쩌면 어떤 아이디어일까요?

    AS3.0에 그런 것이 있으면이 버튼을 클릭하면 mc : MovieClip이 클릭 된 것으로 생각하게됩니다. 그게 뭐니?

    버튼을 사용하여 앞으로 나아갈 수있는 아이디어 ...

    미리 감사드립니다.

+0

두 개의 질문을 두 개의 다른 게시물로 구분해야합니다. – Kodiak

답변

1

goFWD 버튼을 클릭 할 때 트위닝은 어떻게해야합니까? 빠른 모양에서, 나는 당신이 트위스트하려는 thumbnail_group 것 같아요. 그럴까요?

MouseEvent.CLICK 처리기에서 go_oute.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

내가 이미지를 남기고 이미지를 깎아 내고 이미지 전체를 지니고 있다고 썼을 때 .. 어떻게 thumbnai_holder에 대한 e.target을 얻을 수 있습니까? – mrGott

+0

대신 thumbnail_holder를 썼습니다. (전체 -1) <--- 작동하지만 버튼은 한 번만 작동하지만 thumbnail_holder를 클릭하면 제대로 작동합니다. 내 버튼으로 무엇이 잘못 될 수 있습니까? – mrGott