Loading Images upon button clicks in CS4
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Loading Images upon button clicks in CS4

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1

    Loading Images upon button clicks in CS4

    I have a map of a building and I have buttons that I can angle that I wish to load up images to show a friend. I'd ideally like to manually set each picture for each button.

    Can anyone please help me with this code? I would very much appreciate it.

  2. #2
    Junior Member
    Join Date
    Dec 2011
    Location
    Villefranche-sur-mer
    Posts
    8

    Smile


    You will have to make a movie clip to load your images in. A button for each image item you will like to load. After that, make sure to name all your movie clips. For this example I will name the movie clip which will load my images (image). I will name each button (btn1, btn2, btn3, btn4). No we start scripting, this is the simplest code to load my images:

    Code:
    import flash.events.MouseEvent;
    
    btn1.addEventListener(MouseEvent.CLICK, img1);
    btn2.addEventListener(MouseEvent.CLICK, img2);
    btn3.addEventListener(MouseEvent.CLICK, img3);
    btn4.addEventListener(MouseEvent.CLICK, img4);
    
    //copy and paste code
    function img1(evt:MouseEvent):void
    {
    	imageLoad("http://www.rosalinebettencourt.fr/photo/site/art.jpg");
    }
    function img2(evt:MouseEvent):void
    {
    	imageLoad("http://www.rosalinebettencourt.fr/photo/site/art1.jpg");
    }
    function img3(evt:MouseEvent):void
    {
    	imageLoad("http://www.rosalinebettencourt.fr/photo/site/art2.jpg");
    }
    function img4(evt:MouseEvent):void
    {
    	imageLoad("http://www.rosalinebettencourt.fr/photo/site/art3.jpg");
    }
    
    function imageLoad ( file:String )
    {
    	var req:URLRequest = new URLRequest( file );
    	var myLoader:Loader = new Loader();
    	myLoader.load(req);
    	image.addChild(myLoader);
    }
    Now each button will load a different image. If more images are to be loaded, just add more buttons and copy and paste more scripts.
    I have attached the FLA file for a better reference.

    image_buttons.fla


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

Poll by Flashkit.com