A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Simple array question

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Location
    UK
    Posts
    22

    Simple array question

    Hi all,

    I'm bringing a set of filepath data into flash in the standard comma delimited format like this:
    &galpic=/members/1/images/31.jpg,/members/1/images/32.jpg,/members/1/images/33.png,/members/1/images/34.jpg,/members/1/images/35.png,/members/1/images/36.png

    Flash uses this to make a gallery and it works fine. As the user clicks "next" Flash uses the next filepath to pull up that image.

    What I would like to be able to do is display the filepath of each image as it is displayed - so I need to isolate which number in the array flash is using at any given moment. (It will with a button trigger).

    Any ideas ?

    Best wishes
    Monty

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    split to an array using the comma delimiter
    then split the array to separate the numbers -
    PHP Code:
    galpic="/members/1/images/31.jpg,/members/1/images/32.jpg,/members/1/images/33.png,/members/1/images/34.jpg,/members/1/images/35.png,/members/1/images/36.png";

    tmp galpic.split(",");
    len tmp.length;

    for(var 
    n=0;n!=len;n++){
    tmp[n] = tmp[n].split("/");
    tmp[n][4] = tmp[n][4].split(".");
    trace(tmp[n][4][0]);


  3. #3
    Junior Member
    Join Date
    Nov 2009
    Location
    UK
    Posts
    22
    Thanks for the reply.
    So I did a test, set up a dynamic text field with a variable name of "del_pic" then
    put this code on the "next" button.

    on (release) {
    tmp = _root.galpic.split(",");
    len = tmp.length;
    for (var n = 0; n != len; n++) {
    tmp[n] = tmp[n].split("/");
    tmp[n][4] = tmp[n][4].split(".");
    del_pic = (tmp[n][4][0]);
    }
    }

    When tested online "del_pic" returns "undefined".

    Any ideas ?

    Maybe I should mention that the original data is coming through FlashVars from a php file but I can't see that making a great deal of difference.

    Best wishes
    Monty
    Last edited by MiniMonty; 11-13-2009 at 12:30 PM. Reason: More info...

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    when you try -

    PHP Code:
    on(release){
    trace(_root.galpic); // what is the output here ?


  5. #5
    Junior Member
    Join Date
    Nov 2009
    Location
    UK
    Posts
    22
    Can't run a trace (I'm developing live online) but this:

    on (release) {
    del_pic = _root.galpic;
    }

    returns the array (string of filepaths) in the dynamic text box "del_pic".

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    so can you extend the output and show where the code falls down ..
    make del_pic a multiline textfield and --

    on (release) {
    del_pic = _root.galpic;
    tmp = _root.galpic.split(",");
    del_pic += tmp;
    len = tmp.length;
    del_pic += len;
    for (var n = 0; n != len; n++) {
    tmp[n] = tmp[n].split("/");
    tmp[n][4] = tmp[n][4].split(".");
    del_pic += (tmp[n][4][0]);
    }
    }

  7. #7
    Junior Member
    Join Date
    Nov 2009
    Location
    UK
    Posts
    22
    Appreciate your help on this btw...
    Did as suggested and the code returned this in the "del_pic" text box:
    (cut and pasted)


    /members/1/images/31.jpg,/members/1/images/32.jpg,/members/1/images/33.png,/members/1/images/34.jpg,/members/1/images/35.png,
    /members/1/images/36.png,/members/1/images/37.png,/members/1/images/38.jpg,/members/1/images/39.jpg,/members/1/images/40.jpg,
    /members/1/images/41.jpg,/members/1/images/43.jpg,/members/1/images/31.jpg,/members/1/images/32.jpg,/members/1/images/33.png,
    /members/1/images/34.jpg,/members/1/images/35.png,/members/1/images/36.png,/members/1/images/37.png,/members/1/images/38.jpg,
    /members/1/images/39.jpg,/members/1/images/40.jpg,/members/1/images/41.jpg,/members/1/images/43.jpg, 13313233343536373839404143undefined




    I don't understand the output.
    24 filepaths, a 26 digit number (or 26 numbers, or 13 two digit numbers???) and then "undefined".

    I've set up a couple of "tools" to help get this sorted.
    Firstly, the php file is now giving FlashVars a new variable of "allpics" which is the total number of filepaths. (which can of course vary from user to user but "allpics"
    will always be accurate as passed to the Flash front end).
    Secondly I've set up an incrementing counter in a dynamic text field "num" which starts at 0 and goes up by one on every click of the "next" button. This works until
    num == allpics at which point it resets to 0 (so the next click tells "num" to be 1 and therefore tells the gallery to use 1 as the image path to use and causes the
    gallery to loop).

    I'm going to post two blocks of code now so you are not in the dark about how I'm running this whole thing !
    I suppose you should also know that the reason I'm trying to determin the filepath of the image that the Flash Front end is displaying is so users can hit
    a "delete" button and remove that picture from their gallery.

    Code: First is what I use to sort the data coming from php and set up the gallery (frame 1 timeline) and second is the code on the "next" button.
    ("LB" is the left "back" button btw).


    Frame 1 timeline action
    Code:
    import mx.data.components.DataHolder;
    piclist = _root.galpic;
    allpics = _root.allpics;
    photos = piclist.split(",");
    howmany = allpics;
    tellme = allpics +" to see";
    user_num = _root.user;
    if (owner_num == user_num) {
    	cool = "Hi "+_root.firstname+", this is your gallery of all the images you have ever uploaded.\rYou can delete images by clicking the button in the bottom right hand corner.\rBut think carefully because once they're gone - they're gone for good !";
    	setProperty("_root.deleteBtn", _visible, 1);
    }
    //trace(allpics);
    //trace(photos);
    
    var loadListener:Object = new Object();
    loadListener.onLoadInit = function(mc:MovieClip) {
    	mc._x = (Stage.width/2)-(mc._width/2);
    	mc._y = (Stage.height/2)-(mc._height/2+69);
    };
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener(loadListener);
    var nextPhoto:String = photos[num];
    var photoHolder:MovieClip = _root.createEmptyMovieClip("photoHolder", 1);
    mcLoader.loadClip(nextPhoto, photoHolder);
    num = ++num;
    setProperty("LB", _alpha, "40");
    _root.LB.enabled = 0;
    setProperty("_root.backB", _visible, "0");
    //cool = _root.galpic;
    if (allpics==1) {
    	setProperty("LB", _alpha, "40");
    	setProperty("RB", _alpha, "40");
    	_root.LB.enabled = 0;	
    	_root.RB.enabled = 0;	
    }
    // display a message that this user has not uploaded any images yet
    if (allpics == 0) {
    	gotoAndStop(19);
    }

    "Next" button code
    Code:
    on (release) {
    	var loadListener:Object = new Object();
    	loadListener.onLoadInit = function(mc:MovieClip) {
    		mc._x = (Stage.width/2)-(mc._width/2);
    		mc._y = (Stage.height/2)-(mc._height/2+69);
    	};
    	var mcLoader:MovieClipLoader = new MovieClipLoader();
    	mcLoader.addListener(loadListener);
    	var nextPhoto:String = photos[num];
    	var photoHolder:MovieClip = _root.createEmptyMovieClip("photoHolder", 1);
    	mcLoader.loadClip(nextPhoto, photoHolder);
    	num = ++num;
    }
    on (release) {
    	if (num == 1) {
    		setProperty("LB", _alpha, "40");
    		_root.LB.enabled = 0;
    	} else if (num == allpics) {
    		num = "0";
    		setProperty("LB", _alpha, "40");
    		_root.LB.enabled = 0;	
    	} else {
    		setProperty("LB", _alpha, "100");
    		_root.LB.enabled = 1;	
    	}
    }
    If you want to see the whole thing in action it's here:
    www.shutterbugclub.com/main.php

    Sign up - click "Be A Bug" (it's free of course and NO strings attached - I'll purge the whole db
    when it goes live in a few weeks), upload a few pictures and check out your
    own gallery and other members galleries (all me under various guises).
    Should only take five minutes but it will give you a complete idea of what
    it's all about.

    Best wishes
    Monty
    Last edited by MiniMonty; 11-13-2009 at 09:20 PM. Reason: wrote too much !

  8. #8
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Here is a breakdown of your output -

    del_pic = _root.galpic;
    /members/1/images/31.jpg,/members/1/images/32.jpg,/members/1/images/33.png,/members/1/images/34.jpg,/members/1/images/35.png,
    /members/1/images/36.png,/members/1/images/37.png,/members/1/images/38.jpg,/members/1/images/39.jpg,/members/1/images/40.jpg,
    /members/1/images/41.jpg,/members/1/images/43.jpg


    del_pic += tmp;
    /members/1/images/31.jpg,/members/1/images/32.jpg,/members/1/images/33.png,/members/1/images/34.jpg,/members/1/images/35.png,
    /members/1/images/36.png,/members/1/images/37.png,/members/1/images/38.jpg,/members/1/images/39.jpg,/members/1/images/40.jpg,
    /members/1/images/41.jpg,/members/1/images/43.jpg


    del_pic += len;
    13

    del_pic += (tmp[n][4][0])+newline; // should have added newline here
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    43
    undefined


    so as per your original question, the numbers are stored in Flash in the array

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center