A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: if statement question

  1. #1
    Member
    Join Date
    Feb 2004
    Posts
    83

    if statement question

    Hi

    I have a 10 image slide show, each image gets dynamically loaded with this code:

    Code:
    if (_root.contenturl1 == "") {
    	loadMovie("img1intro.jpg", "introimagethingy");
    } else {
    	loadMovie(_root.contenturl1 + "/" + _root.userid + "/img1intro.jpg", "introimagethingy");
    }
    this above code that loads the images along with the movieclip container sits at every 20 frames along with a frame label.

    I'd like to add an "if statement" to check for images loaded, so if image is loaded it goes to play the image frame otherwise it goes and plays the first frame.

    basically I don't want for there to be for example only 2 images and for the slideshow to still go through all the 10 images frames. I want it to check and when it sees that there is no third image to go back and play frame 1.

    I need help with the if statement, I tried putting this on the frame that loads the image:

    Code:
    stop();
    if (_root.contenturl1 + "/" + _root.userid + "/img2intro.jpg") {
    	play();
    } else {
    	gotoAndPlay("Page1");
    }
    ofcouse that didn't work, I'm not sure if this should go on the frame where the image gets loaded or on the previous frame or even if its checking for the right thing.

    any help would b appreciated.
    Last edited by duneglow; 08-15-2008 at 10:33 AM.

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I would use a movieClipLoad() instance..

    it is much more convenient & updated than using loadMovie()

    as a movieClipLoader() has default (callBack) functions that execute automatically on certain states of the loading process

    onLoadStart()
    onLoadProgress()
    onLoaderComplete()
    onLoadInit()
    onLoadError()


    these are there for you to use if you want.

    so for example you load your image (image1 for example)...when it is DONE loading..use the onLoadInit() to start your next action..because you KNOW that your image1 is fully loaded and being displayed.


    in my footer is a link called clipLoader() that gives you steps on how to use it..

    I think this will make things much easier for you.

  3. #3
    Member
    Join Date
    Feb 2004
    Posts
    83
    Hi whispers

    thank you for taking the time to help me

    I tried using the movieClipLoader() but it din't work for me that is why i ended up using the old loadMovie(), I'm sure i used it wrong, could you please tell me how you would successfully apply the movieClipLoader() in place of my loadMovie()?

    Code:
    if (_root.contenturl1 == "") {
    	loadMovie("img1intro.jpg", "introimagethingy");
    } else {
    	loadMovie(_root.contenturl1 + "/" + _root.userid + "/img1intro.jpg", "introimagethingy");
    }
    thanks again


  4. #4
    Member
    Join Date
    Feb 2004
    Posts
    83
    Ok I managed to update my loadmovie code and now I'm using the movieClipLoader() wish yes.. thank you!!.. it is so much better.

    now how do i get to check if the movie loaded into the movie clip container and play(); if it has loaded, else go and play frame 1 ?

    this is the code i'm using

    Code:
    MovieClip.prototype.fadeIn = function() {
    	this.onEnterFrame = function() {
    		if (this._alpha<100) {
    			this._alpha += 10;
    		} else {
    			delete this.onEnterFrame;
    		}
    	};
    };
    bar._visible = false;
    border._visible = false;
    var empty = this.createEmptyMovieClip("container10", "100");
    empty._x = 0 - 100;
    empty._y = 0 - 100;
    my_mc = new MovieClipLoader();
    preload = new Object();
    my_mc.addListener(preload);
    preload.onLoadStart = function(targetMC) {
    	trace("started loading "+targetMC);
    	container10._alpha = 0;
    	bar._visible = true;
    	border._visible = true;
    	pText._visible = true;
    };
    preload.onLoadProgress = function(targetMC, lBytes, tBytes) {
    	bar._width = (lBytes/tBytes)*100;
    	pText.text = "% "+Math.round((lBytes/tBytes)*100);
    };
    preload.onLoadComplete = function(targetMC) {
    	container10.fadeIn();
    	border._visible = false;
    	bar._visible = false;
    	dText._visible = false;
    	trace(targetMC+" finished");
    };
    //default image
    my_mc.loadClip(_root.contenturl1 + "/" + _root.userid + "/img10intro.jpg", "container10");
    I have this code on ten different frames each code loads the image to a different mc container.

    Except for first movie I need to check if all preceding movies are loaded and than perform an action.

    please help.

  5. #5
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    using (for example)

    preload.onLoadInit();

    will execute automatically when the load is done..

    so you can add code in there to do whatever it is you want once the load is done..

    play() or move to another frame..etc

    or you can maybe put some code in the LAST frame of the .swf;s you are loading? are they .swf's? or images?

  6. #6
    Member
    Join Date
    Feb 2004
    Posts
    83
    the are images...

    that code that you suggest that i need to add to the preload.onLoadInit(); is what i need exactly, I'm thinking that it may be an if statement, i just dont know how to add the logic to it.

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    what are you trying to check though? why do you think you need an IF() statement?

    what condition are you checking for? the onLoadInit() ONLY fires when the load is complete and the image is 'visible'

  8. #8
    Member
    Join Date
    Feb 2004
    Posts
    83
    Hi whispers

    Let me explain

    1.this is a 10 image slide show from a multi user gallery

    2.Right now if a user uploads for example 3 out of the 10 images, when viewing the slideshow it displays 3 images plus 7 empty spots and we don't want that, what we want is for it to play the 3 images and go back to frame 1 to replay them again because images 4 through 10 do not exist.

    3. what we want is for there to be some type of check system tat checks whether the next image is loaded or not.

    4. the code checks if image is loaded it, if it is, it goes and plays it, if no image is loaded it goes and plays frame 1.

    so this is why I think an if statement is needed, I just don't know how to put it together, I'm still learning actionscript (very slowly)

    thanks for taking the time to help me.

  9. #9
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    how is the user 'uploading' the images? through Flash?

    you could have a counter that each time your onLoadInit() fires it adds to the counter..and you can use that as the control variable (number) for your loop to only go to say 3 images..and start over..if he uploads another the onLoadInit() adds another increment to the counter var (making it 4) and your code will be capped at only 4 loops/iterations..

    however we need to know more about HOW the user is supplying his images so we can use that as our conditional variable..

  10. #10
    Member
    Join Date
    Feb 2004
    Posts
    83
    That sounds like good Idea whispers, a Php form conducts the upload I don't know how harder that makes things.

    couldn't the checking be done at the point the file occupies the container though?

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