A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Problem checking if a image exist before loading another image

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

    Problem checking if a image exist before loading another image

    Hi guys , I'm new in flash and i'm having a problem using conditional statments in AS2. I'm trying to load a new image
    depending on the image that is allready inside the movieclip. What seems to happen is that flash isn't verifying the
    statments that I have in my code and so the images don't load correctly acorrding to the conditions. I have a movieclip within a movieclip, the first one has an instance name "photo" and the second one is named "empty".

    I'm using this code in one button:


    on (release) {

    if (empty == "Assets/Scroll.png", _root.photo.empty){


    loadMovie("Assets/Photo1.jpg", _root.photo.empty);


    } else if (empty == "Assets/images.jpg", _root.photo.empty){


    loadMovie("Assets/design.jpg", _root.photo.empty);




    gotoAndPlay(6);


    }


    }



    Would someone please help me, I'm loosing my mind

    Thanks!!

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    first... I would try to update your approach to loading images.. to using a clipLoader instance instead (link in my footer if you need it)

    that being said.. I dont think you can 'check' what image has been loaded into a movieClip...
    but you should be able to track it with your own system/code..

    by setting a variable to the image name loaded each time..

    I would do this on the onLoadInit() callback when using a clipLoader() instance..


    do you ONLY need to keep track of what image was loaded into 'EMPTY'? or do you need to also track/know what is loaded into 'movie' (although I dont think anything can? as it will replace the empty clip?)


    Code:
    var imageInEmptyClip:String = "";
    
    // create our MovieClipLoader instance (called: imageLoader)
    var imageLoader:MovieClipLoader = new MovieClipLoader();
    //create an object to handle the data available form the MovieClipLoader() object.
    var imageListener:Object = new Object();
    
    
    // create function that fires/executes when the content starts loading
    imageListener.onLoadStart = function(target_mc:MovieClip):Void  {
    	trace(">> imageListener.onLoadStart()");
    };
    // create function that fires/executes each time a byte/potion is loaded (preloader)
    imageListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void  {
    	trace(">> imageListener.onLoadProgress()");
    };
    // create function that fires/executes when the content is complete
    imageListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void  {
    	trace(">> imageListener.onLoadComplete()");
    };
    // create function that fires/executes when the content has initialized and is ready for manipulation
    imageListener.onLoadInit = function(target_mc:MovieClip):Void  {
    	trace(">> imageListener.onLoadInit()");
    };
    
    
    // add our 'listener' object to our MovieClipLoader instance
    imageLoader.addListener(imageListener);
    
    
    
    //to load some in there initially
    someButton.onPress = function() {
    	imageInEmptyClip = "Scroll.png";
    	// finally, make the call to load whatever content we want.. this is just an on-line image (but can be whatever, .swf, .jpg, clips in library..etc)
    	imageLoader.loadClip("Scroll.png",_root.photo.empty);
    };
    
    //all other consecutive loads
    anotherButton.onPress = function() {
    	if (imageInEmptyClip == "Scroll.png") {
    		imageInEmptyClip = "Photo1.jpg";
    		imageLoader("Assets/Photo1.jpg",_root.photo.empty);
    	} else if (imageInEmptyClip == "Assets/images.jpg") {
    		imageInEmptyClip = "design.jpg";
    		imageLoader("Assets/design.jpg",_root.photo.empty);
    		//gotoAndPlay(6); this will affect main timeline
    	}
    };

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