Results 1 to 5 of 5

Thread: event.currentTarget.name

  1. #1

    Fla Script event.currentTarget.name

    Hi,

    I'm pretty new to coding, and just started an xml gallery, and here i'm stuck trying to access an attribute through a As object/sprite, basically i'm trying to retrieve the .name of the xml child when the sprite is clicked... here is the code and the files linked:

    import fl.containers.UILoader;
    import caurina.transitions.*;

    //---------loading the external xml file-------
    var urlRequest:URLRequest = new URLRequest("pictures.xml");
    var urlLoader:URLLoader = new URLLoader();
    var myXML:XML = new XML();
    var xmlList:XMLList;
    //myXML.ignoreWhitespace = true;
    urlLoader.addEventListener(Event.COMPLETE,fileLoad ed);
    urlLoader.load(urlRequest);

    //--------holds the paths to the thumbnails-------
    var arrayURL:Array = new Array();
    //--------holds the paths to the big photos-------
    var arrayName:Array = new Array();
    //--------holds the thumbnail objects-------
    var holderArray:Array = new Array();
    var arraytext1:Array = new Array();

    //-------represents the container of our gallery
    var sprite:Sprite = new Sprite();
    addChild(sprite);
    var thumb:Thumbnail;
    //-------- the thumbnails container-------
    var thumbsHolder:Sprite = new Sprite();
    sprite.addChild(thumbsHolder);
    //-------- the photoLoader container-------
    var loaderHolder:Sprite = new Sprite();
    //loaderHolder.graphics.beginFill(0xffffff,1);
    //loaderHolder.graphics.drawRect(0,0,550,330);
    //loaderHolder.graphics.endFill();
    loaderHolder.x = 10;
    loaderHolder.y = 10;
    sprite.addChild(loaderHolder);
    //-------- loads the big photo-------
    var photoLoader:UILoader = new UILoader();
    photoLoader.width = 600;
    photoLoader.height = 400;
    photoLoader.y = 5;
    photoLoader.x = 5;
    //photoLoader.buttonMode = true;
    photoLoader.addEventListener(MouseEvent.CLICK,onCl ickBack);
    loaderHolder.addChild(photoLoader);

    var cartel:TextField = new TextField;
    cartel.x = 5;
    cartel.y = 5;
    cartel.width = 110;
    cartel.autoSize = TextFieldAutoSize.LEFT;
    cartel.selectable = false;
    addChild(cartel);
    //cartel.text = picTitle;


    /* we loop through the xml file
    populate the arrayURL, arrayName and position the thumbnalis*/
    function fileLoaded(event:Event):void {
    myXML = XML(event.target.data);
    xmlList = myXML.children();

    for (var i:int=0; i<xmlList.length(); i++) {
    var picURL:String = xmlList[i].url;
    var picTitle :String= String(xmlList[i].attribute("name"));
    var picName:String = xmlList[i].big_url;
    arrayURL.push(picURL);
    arrayName.push(picName);
    arraytext1.push(picTitle);
    holderArray[i] = new Thumbnail(arrayURL[i],i,arrayName[i]);
    holderArray[i].addEventListener(MouseEvent.CLICK,onClick);
    holderArray[i].name = arrayName[i];
    //holderArray[i].titre = arraytext1[i];//holderArray[i].title = picTitle[i];

    trace(picTitle);
    holderArray[i].y = 65;
    holderArray[i].x = i*110+65;
    thumbsHolder.addChild(holderArray[i]);
    if (i>7) {
    thumbsHolder.addEventListener(MouseEvent.MOUSE_OVE R, slide);
    }
    }
    }

    //----handles the Click event added to the thumbnails--
    function onClick(event:MouseEvent):void {
    photoLoader.source = event.currentTarget.name;

    Tweener.addTween(loaderHolder, {alpha:1, time:1, transition:"linear"});
    }
    //----handles the Click event added to the photoLoader----
    function onClickBack(event:MouseEvent):void {

    Tweener.addTween(loaderHolder, {alpha:0, time:2, transition:"linear"});
    //thumbsHolder.removeChild;
    }

    function slide(event:MouseEvent){
    //if (mouseX > 660){Tweener.addTween(thumbsHolder, {x:0, time:1, transition:"easeIn"});}
    }




    //the .as file
    //____________________________________________

    package {
    import flash.display.Sprite;
    import fl.containers.UILoader;
    import caurina.transitions.*;
    import flash.events.MouseEvent;

    public class Thumbnail extends Sprite {
    private var nume:String;
    private var url:String;
    public var id:int;
    private var loader:UILoader;
    public var nom:String;
    public var itemNr:int;

    function Thumbnail(source:String,itemNr:int,numeThumb:Strin g):void {
    url = source;
    id = itemNr;
    name = nom;//nom = picTitle[itemNr];
    this.nume = numeThumb;
    drawLoader();
    addEventListener(MouseEvent.MOUSE_OVER,onOver);
    addEventListener(MouseEvent.MOUSE_OUT,onOut);
    scaleThumb();
    }

    private function drawLoader():void {
    loader = new UILoader();
    loader.source = url;
    loader.mouseEnabled = false;
    loader.x = 0;
    loader.y = 0;
    addChild(loader);

    }
    private function onOver(event:MouseEvent):void {
    Tweener.addTween(this, {scaleX:1,scaleY:1, time:1, transition:"easeout"});
    Tweener.addTween(this, {alpha:1, time:1, transition:"easeout"});
    }
    private function onOut(event:MouseEvent):void {
    Tweener.addTween(this, {scaleX:.9,scaleY:.9, time:1, transition:"easeout"});
    Tweener.addTween(this, {alpha:.5, time:1, transition:"easeout"});
    }
    private function scaleThumb():void {
    this.scaleX = .9;
    this.scaleY = .9;
    this.alpha = .5;
    }
    }
    }
    Attached Files Attached Files

  2. #2
    Hi,
    did you manage to make it show the picture title?
    That is where I am stuck

  3. #3
    urlLoader.addEventListener(Event.COMPLETE,fileLoad ed);
    photoLoader.addEventListener(MouseEvent.CLICK,onCl ickBack);
    why are there spaces in the middle of the listener's names?

    "A human can interpret missing logic but a computer can't." - wkt
    "That goes into the 'too bad' box." - TOdorus
    "This is a three year old thread, there's no reason to post here..." - flyingmonkey456
    "Despite beeing the oposite, they look very similar to me." - SparK

  4. #4

    XML target info..

    Yes I did but it is a bit awkward, i'm using the thumbs.name but it is a bit random.. since it doesn't work when the number of thumbnails to display changes for example, but it is a try, let mer know if you can improve this:


    // create array and thumbnails

    myXML = XML(event.target.data);
    xmlList = myXML.children();
    var i:int;
    var p:int;
    var picURL:String;
    var picTitle :String;
    var picDate:String;
    var picSize:String;
    var picName:String;


    p=0;

    for (i=0; i<xmlList.length(); i++) {

    picType= String(xmlList[i].attribute("cat"));
    if (picType == typeChoisi) {

    picTitle = String(xmlList[i].attribute("name"));
    if (picTitle == ""){picTitle = "Untitled";}
    picDate = String(xmlList[i].attribute("date"));
    picSize = String(xmlList[i].attribute("size"));
    picURL = xmlList[i].url;
    picName= xmlList[i].big_url;
    arrayURL.push(picURL);
    arrayName.push(picName);
    arraytext1.push(picTitle);
    arrayDate.push(picDate);
    arraySize.push(picSize);
    holderArray[p] = new Thumbnail(arrayURL[p],p,arrayName[p]);
    holderArray[p].addEventListener(MouseEvent.CLICK,onClick);
    //holderArray[i].name = arrayURL[i];
    holderArray[p].name = p;
    trace(picTitle);
    //var _titre:String = arraytext1[p];
    holderArray[p].y =715;
    holderArray[p].x = 1160 - p*110;

    thumbsHolder.addChild(holderArray[p]);
    p++;
    }


    gallerySize = thumbsHolder.width;

    thumbsHolder.addEventListener(MouseEvent.MOUSE_OVE R, slide);
    thumbsHolder.addEventListener(MouseEvent.ROLL_OUT, stopScroll);

    }

    //_______________________
    //the text when a thunmbnail is clicked

    numero = event.target.name.substring(8,event.target.name.le ngth);
    realNum = (Number(numero)-38)/9;//**this operation is quite random!!**
    frameLoader.source = arrayURL[realNum];//event.currentTarget.name;
    //cartel.text = arraytext1[realNum];//event.currentTarget.name;
    if ((arrayDate[realNum] != "") && (arraySize[realNum] != "")){cartel.text =((arraytext1[realNum])+":"+arrayDate[realNum]+":"+(arraySize[realNum]));}
    else if ((arrayDate[realNum] = "") && (arraySize[realNum] = "")){cartel.text =(arraytext1[realNum]);}
    else if ((arrayDate[realNum] != "") && (arraySize[realNum] = "")){cartel.text =((arraytext1[realNum])+":"+(arrayDate[realNum]));}
    else if ((arrayDate[realNum] = "") && (arraySize[realNum] != "")){cartel.text =(arraytext1[realNum])+":"+(arraySize[realNum]);}
    trace(realNum);
    trace(event.target.name);

  5. #5

    XML unload

    Hi again, I found a way to get the info of my "thumbnail" displayed, but i'd like to display a different serie of thumbnail on click of a button,

    i can get different series by clicking on different buttons, but can't unload and "renew", when i click on a second button, the it adds the same serie of thumbs to stage,
    How can i unload my uiloader ? addchild/removechild doesn't seem to be the answer here.
    oh, and by the way my solution to display the info of a thumbnail doesn't seem to work anymore...


    here the code:


    //---------loading the external xml file-------
    var urlRequest:URLRequest = new URLRequest("pictures.xml");
    var urlLoader:URLLoader = new URLLoader();
    var myXML:XML = new XML();
    var xmlList:XMLList;
    //myXML.ignoreWhitespace = true;

    function loadPix(event:MouseEvent){
    urlLoader.addEventListener(Event.COMPLETE,fileLoad ed);
    urlLoader.load(urlRequest);}

    function fileLoadok(event:Event){
    parsage = true;
    }
    //--------holds the paths to the thumbnails-------
    var arrayURL:Array = new Array();
    //--------holds the paths to the big photos-------
    var arrayName:Array = new Array();
    var arrayDate:Array = new Array();
    var arraySize:Array = new Array();
    //--------holds the thumbnail objects-------
    var holderArray:Array = new Array();
    var arraytext1:Array = new Array();

    //-------represents the container of our gallery
    var sprite:Sprite = new Sprite();
    addChild(sprite);

    //var thumb:Thumbnail;

    //-------- the thumbnails container-------
    var thumbsHolder:MovieClip = new MovieClip();
    //sprite.addChild(thumbsHolder);

    //-------- the photoLoader container-------
    var loaderHolder:Sprite = new Sprite();
    loaderHolder.x = 0;
    loaderHolder.y =0;
    //sprite.addChild(loaderHolder);
    addChild(loaderHolder);
    //-------- the photoLoader container-------
    var bigLoaderHolder:Sprite = new Sprite();
    bigLoaderHolder.x = 0;
    bigLoaderHolder.y =0;
    //sprite.addChild(bigLoaderHolder);
    addChild(bigLoaderHolder);

    //-------- loads the big photo-------
    var frameLoader:UILoader = new UILoader();
    frameLoader.width = 650;
    frameLoader.height = 450;
    frameLoader.x = 605;
    frameLoader.y = 205;
    //photoLoader.buttonMode = true;
    frameLoader.addEventListener(MouseEvent.CLICK,clic kToBig);
    loaderHolder.addChild(frameLoader);
    //addChild(frameLoader);
    ;
    //______text attempt_______
    var cartel:TextField = new TextField;
    //cartel.x = photoLoader.x -5;
    cartel.x =frameLoader.x -100;
    cartel.y =630;// photoLoader.y +photoLoader.height ;
    cartel.width = 110;
    cartel.autoSize = TextFieldAutoSize.RIGHT;
    cartel.defaultTextFormat = title_style;
    cartel.selectable = false;
    cartel.alpha = 0.5;
    loaderHolder.addChild(cartel);
    //addChild(cartel);
    //cartel.text = picTitle;
    //-------- loads the big photo-------
    var photoLoader:UILoader = new UILoader();
    photoLoader.width =largeur1;
    photoLoader.height =950;
    photoLoader.y =0;
    photoLoader.x =0;
    //photoLoader.buttonMode = true;
    photoLoader.addEventListener(MouseEvent.CLICK,onCl ickBack);
    //bigLoaderHolder.addChild(photoLoader);
    //addChild(photoLoader)

    /*we loop through the xml file populate the arrayURL, arrayName and position the thumbnalis*/
    var picType:String;
    var typeChoisi:String;


    function fileLoaded(event:Event):void {
    // myXML.unload;
    //if (this.contains (thumbsHolder)){removeChild(thumbsHolder);}
    myXML = XML(event.target.data);
    xmlList = myXML.children();
    var i:int;
    var p:int;
    var picURL:String;
    var picTitle :String;
    var picDate:String;
    var picSize:String;
    var picName:String;
    //var picType:String;
    //trace ("dedans");
    trace(typeChoisi);
    // trace (parsage);
    p=0;
    if (parsage = true){
    for (i=0; i<xmlList.length(); i++) {
    //trace (typeChoisi);

    picType= String(xmlList[i].attribute("cat"));
    if (picType == typeChoisi) {

    picTitle = String(xmlList[i].attribute("name"));
    if (picTitle == ""){picTitle = "Untitled";}
    picDate = String(xmlList[i].attribute("date"));
    picSize = String(xmlList[i].attribute("size"));
    picURL = xmlList[i].url;
    picName= xmlList[i].big_url;
    arrayURL.push(picURL);
    arrayName.push(picName);
    arraytext1.push(picTitle);
    arrayDate.push(picDate);
    arraySize.push(picSize);
    holderArray[p] = new Thumbnail(arrayURL[p],p,arrayName[p]);
    holderArray[p].addEventListener(MouseEvent.CLICK,onClick);
    //holderArray[i].name = arrayURL[i];
    holderArray[p].name = p;
    trace(picTitle);
    //var _titre:String = arraytext1[p];
    holderArray[p].y =715;
    holderArray[p].x = 1160 - p*110;
    //cartel.text = arraytext1[i];

    thumbsHolder.addChild(holderArray[p]);
    p++;
    }


    gallerySize = thumbsHolder.width;
    //trace("gallerySize:" +gallerySize);
    thumbsHolder.addEventListener(MouseEvent.MOUSE_OVE R, slide);
    thumbsHolder.addEventListener(MouseEvent.ROLL_OUT, stopScroll);
    }
    }
    }



    function be(event:MouseEvent) {
    if (event.currentTarget.name == "_btn0")
    {
    typeChoisi ="landscape";
    if (this.contains (thumbsHolder)){sprite.removeChild(thumbsHolder);}
    //loadPix(event);
    sprite.addChild(thumbsHolder);
    if (txt==true)
    {
    removeChild(texte);
    txt = !txt;
    }
    a=0;
    if (a!=b) {
    //trace(a);
    //trace(b);
    galleryChange = true;
    }
    b=a;
    }

    else if (event.currentTarget.name == "_btn1")
    {typeChoisi ="portrait";
    if (this.contains (thumbsHolder)){sprite.removeChild(thumbsHolder);}

    loadPix(event);
    sprite.addChild(thumbsHolder);


    if (txt==true) {
    removeChild(texte);
    txt = !txt;
    }
    a=1;
    if (a!=b) {
    trace(a);
    galleryChange = true;
    }
    b=a;
    }

    else if (event.currentTarget.name == "_btn2") {
    typeChoisi ="abstract";
    if (txt==true) {
    removeChild(texte);
    txt = !txt;
    loadPix(event);

    }
    a=2;
    if (a!=b) {
    trace(a);
    galleryChange = true;
    }
    b=a;
    }


    else if (event.currentTarget.name == "_btn3") {
    if (txt==false) {
    addChild(texte);
    txt = !txt;
    }
    a=3;
    }


    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012