Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 12

Thread: PREV and NEXT buttons ; 3.0

  1. #1
    Junior Member Settled In xPINKMERCEDESx is on a distinguished road
    Join Date
    Feb 2009
    Posts
    27
    Rep Power
    0

    PREV and NEXT buttons ; 3.0

    amazing Flash templates
    Hello guys. I ran into another wall, and it's just my inexperience. I'm getting experience by the day and by the project.


    Here's my problem. I'm trying to build a simple photo gallery with Next and Previous buttons without alot of classes and any xml and alot of code. The image locations are in an array. Also, I need the name of the current image to be stored in a variable for other purposes. Here's the latest version of my code; I've been trying alot of things to no avail guys:


    var myPlace:Loader = new Loader();
    myPlace.x=50.0
    myPlace.y=50.0
    addChild(myPlace);

    var theImages:Array=new Array("mercedes1","mercedes2","mercedes3");

    var currentImage:Number;
    var previousImage:Number;
    var currentImageName=event.target;

    prevImage.addEventListener(MouseEvent.CLICK,prevCl icked,false,0,true);
    nextImage.addEventListener(MouseEvent.CLICK,nextCl icked,false,0,true);

    myPlace.load(new URLRequest(theImages[0]));


    function prevClicked(event:MouseEvent):void
    {
    previousImage = previousImage-1;
    if (previousImage<=0) {
    previousImage = 3;
    }
    myPlace.load(new URLRequest(theImages + previousImage + ".jpg"));
    previousImage --;
    currentImageName=currentImageName;
    }

    function nextClicked(event:MouseEvent):void
    {
    if (currentImage>=3)
    {
    currentImage = 0;
    }
    myPlace.load(new URLRequest(theImages + currentImage + ".jpg"));
    currentImage++;
    currentImageName=currentImageName;
    }



    Thanks for any direction guys.


    x lisa x

  2. #2
    Member Settled In Matita is on a distinguished road
    Join Date
    Mar 2009
    Posts
    31
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    Hi!
    This code should work:

    PHP Code:
    var myPlace:Loader = new Loader();
    myPlace.x=50.0
    myPlace
    .y=50.0
    addChild
    (myPlace);

    var 
    theImages:Array=new Array("mercedes1","mercedes2","mercedes3");

    var 
    currentImage:Number;

    prevImage.addEventListener(MouseEvent.CLICK,prevClicked,false,0,true);
    nextImage.addEventListener(MouseEvent.CLICK,nextClicked,false,0,true);

    myPlace.load(new URLRequest(theImages[0] + ".jpg"));


    function 
    prevClicked(event:MouseEvent):void
    {
        
    currentImage--;
        if (
    currentImage 0) {
            
    currentImage theImages.length 1;
        }
        
    myPlace.load(new URLRequest(theImages[currentImage] + ".jpg"));
    }

    function 
    nextClicked(event:MouseEvent):void
    {
        
    currentImage++;
        if (
    currentImage >= theImages.length)
        {
            
    currentImage 0;
        }
        
    myPlace.load(new URLRequest(theImages[currentImage] + ".jpg"));

    all you need is the index 'currentImage' (not 'previousImage' or 'currentImageName').
    That's the index you increment or decrement to switch among the images.
    I've changed the line
    PHP Code:
    if (currentImage>=3
    {
        
    currentImage 0;

    in
    PHP Code:
    if (currentImage >= theImages.length)
    {
        
    currentImage 0;

    so anytime you want you can add or remove items from the array without changing any other line of code.
    Hope it's been useful

  3. #3
    Junior Member Settled In xPINKMERCEDESx is on a distinguished road
    Join Date
    Feb 2009
    Posts
    27
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    Thanks for the reply Matita.

    I copied and pasted your code and I'm still getting an error message:


    Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.


    Flash can't find the URL, so I know some code is needed to tell Flash to get the images from the theImages array...

    and the reason currentImageName was there is because I need to store the name of the last image that was loaded into a variable for other purposes.


    thanks again.



    x lisa x

  4. #4
    Junior Member Settled In xPINKMERCEDESx is on a distinguished road
    Join Date
    Feb 2009
    Posts
    27
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    I figured it out ...whew...now i need to figure how to store the name of the image that was loaded...here's the fixed code:


    var myPlace:Loader = new Loader();
    myPlace.x=50.0
    myPlace.y=50.0
    addChild(myPlace);

    var theImages:Array=new Array("mercedes1","mercedes2","mercedes3");
    var currentImage:Number=0;

    //var currentImageName:String;

    prevImage.addEventListener(MouseEvent.CLICK,prevCl icked,false,0,true);
    nextImage.addEventListener(MouseEvent.CLICK,nextCl icked,false,0,true);

    myPlace.load(new URLRequest(theImages[0]+".jpg"));

    function nextClicked(event:MouseEvent):void
    {
    if (currentImage < (theImages.length-1))
    {
    currentImage ++;
    myPlace.load(new URLRequest(theImages[currentImage] + ".jpg"));
    }
    }

    function prevClicked(event:MouseEvent):void
    {
    if (currentImage > 0)
    {
    currentImage-- ;
    myPlace.load(new URLRequest(theImages[currentImage] + ".jpg"));
    }
    }


    all I need is to know how to store the name of the image currently being viewed in a variable, such as

    var currentImageName=?


    thanks everyone...


    x lisa x
    Last edited by xPINKMERCEDESx; 10-04-09 at 03:14.

  5. #5
    Junior Member Settled In flamboyant is on a distinguished road
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    just add this in your functions for the buttons----->


    currentImageName=theImages[currentImage];

    // then trace it to test the code

    trace(currentImageName);



    FLAMBOYANT

  6. #6
    Member Settled In Matita is on a distinguished road
    Join Date
    Mar 2009
    Posts
    31
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    Actually you don't really need to store the current image name in some variables because you can get it whenever you want just with
    theImages[currentImage];

    What I understood from your first post was that you needed the previous image you displayed.
    In case this is what you need than you can write this way:

    PHP Code:
    var previousImage:Number 0;

    function 
    nextClicked(event:MouseEvent):void
    {
        
    showPicture(currentImage 1);
    }

    function 
    prevClicked(event:MouseEvent):void
    {
        
    showPicture(currentImage 1);
    }

    function 
    showPicture(index:Number):void {
        
    previousImage currentImage;
        if (
    index 0)
            
    index theImages.length 1;
        else if (
    index >= theImages.length)
            
    index 0;
        
    currentImage index;
        
    myPlace.load(new URLRequest(theImages[currentImage] + ".jpg"));

    By doing this you put all the actions in a single function and anytime you want to navigate among the pictures you use the function showPicture(n).
    Plus, if you want to change or bugfix something you modify the code only in one place ;)
    Plus, if you are viewing the first picture and want to see the fourth one you just write showPicture(3); (imagine you have a set of thumbnails and want to see a specific picture without navigating one by one...)

    In 'previousImage' you store the last index you visited, so you can have the name of the previous image by 'theImages[previousImage]', and if you have a 'back' button you can navigate to the last picture by 'showPicture(previousImage)'

    But maybe you don't need all these features...

  7. #7
    Junior Member Settled In xPINKMERCEDESx is on a distinguished road
    Join Date
    Feb 2009
    Posts
    27
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    cool Matita...I understand these things now...my photo gallery is working the way i want it to. Just for the record I wanted the variable to store the last image loaded and not the previous image loaded, but that's okay...with all the replies I got it now..thanks so much...and thanks to flamboyant too...


    x lisa x

  8. #8
    Junior Member Settled In armaluca is on a distinguished road
    Join Date
    Jun 2009
    Posts
    11
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    Hi guys ,i tried to implement this code for my gallery
    but when i click the next button to go over the last image in "images_array" i receive the error
    TypeError: Error #2007: Parameter url must be non-null.

    the same when i click prev button to go before the first image in the array
    where-s the problem?

    thanks!
    Code:
    
    next_btn.addEventListener(MouseEvent.CLICK,nextClicked);
    prev_btn.addEventListener(MouseEvent.CLICK,prevClicked);
    
       function nextClicked(event:MouseEvent):void
    {
        showPicture(currentImage + 1);
    }
    
    function prevClicked(event:MouseEvent):void
    {
        showPicture(currentImage - 1);
    }
    
    function showPicture(reference:Number):void {
       
       var urlRequest:URLRequest=new URLRequest(images_array[reference]);
    			
       loader.load(urlRequest);
    
       container.addChild(loader);
       
       
       currentImage = reference;
        if (reference < 0)
            	reference = images_array.length - 1;
        else if (reference >= images_array.length)
            	reference = 0;
        
        
    }

  9. #9
    Member Settled In Matita is on a distinguished road
    Join Date
    Mar 2009
    Posts
    31
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    you have to change reference before creating URLRequest object:

    Code:
    function showPicture(reference:Number):void {
       
    currentImage = reference;
        if (reference < 0)
            	reference = images_array.length - 1;
        else if (reference >= images_array.length)
            	reference = 0;
    
       var urlRequest:URLRequest=new URLRequest(images_array[reference]);
    			
       loader.load(urlRequest);
    
       container.addChild(loader);
       
    }

  10. #10
    Junior Member Settled In armaluca is on a distinguished road
    Join Date
    Jun 2009
    Posts
    11
    Rep Power
    0

    Re: PREV and NEXT buttons ; 3.0

    now i dont receive the error message but by clicking on the next_btn over and over ,after the images_array.lenght i succed to display always images_array[0] (even if i click for ever).

    the same if i go backward with the prev_btn.. always the images_array[0] is displayied on stage..

    where am i wrong??
    thanks

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Similar Threads

  1. buttons open in new windows
    By davidbanga in forum HELP free utilities
    Replies: 2
    Last Post: 11-09-09, 11:39
  2. next button-prev button+transizioni+tante altre cose
    By filippot in forum Actionscript 3.0 base
    Replies: 3
    Last Post: 19-06-09, 17:56
  3. XML photo gallery with prev/next buttons
    By Rain in forum advanced Actionscript 3.0
    Replies: 1
    Last Post: 22-01-09, 02:14
  4. buttons
    By Zombie in forum Actionscript 3.0 newbies
    Replies: 14
    Last Post: 19-08-08, 16:32
  5. buttons dissolvenza
    By michele77 in forum Flash Italiano
    Replies: 8
    Last Post: 12-12-07, 21:26

Bookmarks

Posting Permissions

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

Search Engine Optimization by vBSEO