A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: if url not found

  1. #1
    Senior Member
    Join Date
    May 2016
    Posts
    451

    if url not found

    hello all

    this is function to load smooth external images

    PHP Code:
    onFrame (1) {

        
    MovieClip.prototype.LoadSmoothImage = function(Url,maxW,maxH,redraw) {
            
    this.createEmptyMovieClip("mc",this.getNextHighestDepth());
            
    this.mc.loadMovie(Url);              
            
    this.onEnterFrame = function() {
                if (
    this.mc.getPercentLoaded() == 100) { 
                    
    delete this.onEnterFrame 
                    this
    .mc._xscale this.mc._yscale 100;       
                    
    this.ow this.mc._width;
                    
    this.oh this.mc._height;
                    
    this.x_ratio maxW this.ow;
                    
    this.y_ratio maxH this.oh
                    if (
    this.mc._width maxW || this.mc._height maxH) {
                        if ((
    this.x_ratio this.oh) < maxH) {
                            
    this.mc._height Math.ceil(this.x_ratio this.oh);
                            
    this.mc._width this.size._width;
                        } else {
                            
    this.mc._width Math.ceil(this.y_ratio this.ow);
                            
    this.mc._height maxW;
                        }
                    }            
                    if (
    redraw) {
                        
    this.bitmap=new flash.display.BitmapData(this.mc._width,this.mc._heighttrue0xff0000);
                                        
                        
    this.mc.attachBitmap(this.bitmap,this.mc.getNextHighestDepth(),"auto",true);
                        
    this.bitmap.draw(this.mc);      
                        
    this.mc.forceSmoothing true ;      
                        }                    
                    
                    }
                }
            }
            for( 
    i=1;10;i++){
               
       
    _parent["mc"+i].LoadSmoothImage(String(i)+".jpg",320,320,true);    
        }
             


    i want add code to this function if image not found in url path

    ex

    if_parent["mc"+i] not found (i) .jpg====> parent["mc"+i] load "0.jpg"

    thanks for help

  2. #2
    Senior Member
    Join Date
    May 2016
    Posts
    451
    I tried a lot but I didn't succeed in solving it
    Any Help

  3. #3
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello,

    Inside of the this.enterFrame function if this.mc.getBytesTotal() is ever equal to -1 for "unnown.png" that means it is not a valid url, so it will load "unknown.png" spelled properly inside of the if statement.
    PHP Code:
    onFrame (1) {

        
    MovieClip.prototype.LoadSmoothImage = function(Url,maxW,maxH,redraw) {

            
    this.createEmptyMovieClip("mc",this.getNextHighestDepth());
            
    this.mc.loadMovie(Url);         
                         
            
    this.onEnterFrame = function() {
                
    if(
    this.mc.getBytesTotal()==-1){                   
    _parent["mc"+1].LoadSmoothImage(file_path+"unknown.png",320,320,true);//Load it spelled properly.
    }
                  
                if (
    this.mc.getPercentLoaded() == 100) { 
                 
                     
                  
                  
               
                    
    delete this.onEnterFrame 
                    this
    .mc._xscale this.mc._yscale 200;       
                    
    this.ow this.mc._width;
                    
    this.oh this.mc._height;
                    
    this.x_ratio maxW this.ow;
                    
    this.y_ratio maxH this.oh
                    if (
    this.mc._width maxW || this.mc._height maxH) {
                        if ((
    this.x_ratio this.oh) < maxH) {
                            
    this.mc._height Math.ceil(this.x_ratio this.oh);
                            
    this.mc._width this.size._width;
                        } else {
                            
    this.mc._width Math.ceil(this.y_ratio this.ow);
                            
    this.mc._height maxW;
                        }
                    }            
                    if (
    redraw) {
                        
    this.bitmap=new flash.display.BitmapData(this.mc._width,this.mc._heighttrue0xff0000);
                                        
                        
    this.mc.attachBitmap(this.bitmap,this.mc.getNextHighestDepth(),"auto",true);
                        
    this.bitmap.draw(this.mc);      
                        
    this.mc.forceSmoothing true ;      
                        }                    
                    
                    }
                }
            }
            
        
    var 
    file_path:String="C:\\Users\\Desktop\\Desktop\\movie\\myfolderImages\\"
    _parent["mc"+1].LoadSmoothImage(file_path+"unnown.png",320,320,true);    

           
                  

    Last edited by AS3.0; 01-14-2023 at 08:11 AM.

  4. #4
    Senior Member
    Join Date
    May 2016
    Posts
    451
    Last edited by kofa; 01-14-2023 at 09:07 AM.

  5. #5
    Senior Member
    Join Date
    May 2016
    Posts
    451
    thank you very very much

  6. #6
    Senior Member
    Join Date
    May 2016
    Posts
    451
    invalid url for loop not working
    can you add for loop to valid url and invalid url
    please

  7. #7
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hi,

    This is the source inside of the first mc:
    PHP Code:
    onFrame (1) {

        
    MovieClip.prototype.LoadSmoothImage = function(Url,maxW,maxH,redraw) {

            
    this.createEmptyMovieClip("mc",this.getNextHighestDepth());
            
    this.mc.loadMovie(Url);         
                         
            
    this.onEnterFrame = function() {
                
    if(
    this.mc.getBytesTotal()==-1){                   
    _parent["mc"+this._name.split("c")[1]].LoadSmoothImage(file_path+"unknown.png",320,320,true);//Load "unknown.png" for mc: this._name.split("c")[1], splitting after the letter "c" of "mc" to retrieve the mc number.
    }
                  
                if (
    this.mc.getPercentLoaded() == 100) { 
                 
                     
                  
                  
               
                    
    delete this.onEnterFrame 
                    this
    .mc._xscale this.mc._yscale 200;       
                    
    this.ow this.mc._width;
                    
    this.oh this.mc._height;
                    
    this.x_ratio maxW this.ow;
                    
    this.y_ratio maxH this.oh
                    if (
    this.mc._width maxW || this.mc._height maxH) {
                        if ((
    this.x_ratio this.oh) < maxH) {
                            
    this.mc._height Math.ceil(this.x_ratio this.oh);
                            
    this.mc._width this.size._width;
                        } else {
                            
    this.mc._width Math.ceil(this.y_ratio this.ow);
                            
    this.mc._height maxW;
                        }
                    }            
                    if (
    redraw) {
                        
    this.bitmap=new flash.display.BitmapData(this.mc._width,this.mc._heighttrue0xff0000);
                                        
                        
    this.mc.attachBitmap(this.bitmap,this.mc.getNextHighestDepth(),"auto",true);
                        
    this.bitmap.draw(this.mc);      
                        
    this.mc.forceSmoothing true ;      
                        }                    
                    
                    }
                }
            }
            
        
    var 
    file_path:String="C:\\Users\\Desktop\\Desktop\\movie\\myfolderImages\\"

    for(var i=0;i<10;i++){
    _parent["mc"+i].LoadSmoothImage(file_path+String(i)+".png",320,320,true);    //file_path + i which is 0-9 .png
    }
           
                  

    Send me your file if it is still not working.

    download v1 (swish)
    Last edited by AS3.0; 01-14-2023 at 02:27 PM.

  8. #8

  9. #9
    Senior Member
    Join Date
    May 2016
    Posts
    451
    try to delete image number 4 or any ===> there is 4 unknown.png appear

    i want if image [i] not found ==> only this image load unknown.png

  10. #10
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Ok the first mc will be mc1... to mc10.

    download v3 (swish)
    Last edited by AS3.0; 01-14-2023 at 04:03 PM.

  11. #11
    Senior Member
    Join Date
    May 2016
    Posts
    451
    you are AS2 golden man
    thanks

  12. #12
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    I changed it to v3, no problem.

  13. #13
    Senior Member
    Join Date
    May 2016
    Posts
    451
    what is v3 ???

  14. #14
    Senior Member
    Join Date
    May 2016
    Posts
    451
    in test 4 : https://app.box.com/s/rztkcu5gu4qt6r6q8uxpngf9n59kw21z

    i want :

    1- add onRollOver , onRollOut , onpress functions for only loaded image

    it maen : if mc not loaded image ===> mc .enabled = false and remove onRollOver , onRollOut , onpress functions

    2- when onRollOver ===> stroke1._x=this mc._x and stroke1._visible=true
    3- when onRollOut ===> stroke1._visible=false


    4 when onpress

    A- if this the first mc pressed ===> strok1 visible but if pressed this mc again strok1 no visible

    B- if pressed another ===> strok2 visible

    c- if 2 mc pressed ===> waite 2 second and trace(" ready ")
    Last edited by kofa; 01-15-2023 at 04:34 AM.

  15. #15
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hi,

    At the images scripting section you have the colors for stroke_color_1 which is red & for stroke_color_2 which is green:
    PHP Code:
    var stroke_color_1:Number=0xFF0000//Red.
    var stroke_color_2:Number=0x00FF00//Green. 
    PHP Code:
    onSelfEvent (load) {
        
    stroke1._visible false;
        
    stroke2._visible false;
    }




    var 
    stroke_size:Number=5
    var stroke_color_1:Number=0xFF0000
    var stroke_color_2:Number=0x00FF00
    var timeout=null//Variable to store the 2 second delayed function call.

    function ready(){
    trace("ready")//Call in 2 seconds if more than 2 images are selected at the stroke 2 setting.
    }
    var 
    selected_items:Array=new Array();//This array stores all of the images that are currently with stroke_1 or stroke_2.
    var found_bin:Array=new Array();//This array will be used to give all of the images stroke 2 if the size is greater than 1.
    function checkMultiple(){//Check multiples and modify the stroke color to stroke 2.
    found_bin=new Array();
    for(var 
    i=0;i<selected_items.length;i++){//Search through the full array of selected images.
    if(selected_items[i]!=undefined){//If the array element is not undefined it can be identified as an image.
    found_bin.push(selected_items[i])//Add the image to the found bin.
    }
    }

    if(
    found_bin.length>1){//If the found bin has > 1 items, give all of the selected images the second stroke color.
    clearTimeout(timeout)//Clear timeout if rapidly pressing more images so multiple ready function calls don't happen.
    timeout=setTimeout(ready,2000);//Create a new timeout in 2 seconds & store it inside the variable called timeout.
    for(var i=0;i<found_bin.length;i++){//Loop through all of the images in found_bin & set the new stroke color.
    found_bin[i].clear()//Clear the previous stroke color.
    found_bin[i].lineStyle(stroke_size,stroke_color_2);//Draw the stroke rectangle.
    found_bin[i].moveTo(-stroke_size,-stroke_size);
    found_bin[i].lineTo(found_bin[i]._width+(stroke_size),-stroke_size);
    found_bin[i].lineTo(found_bin[i]._width-(stroke_size*2),found_bin[i]._height+(stroke_size*1)-(stroke_size*1.5));
    found_bin[i].lineTo(-stroke_size,found_bin[i]._height-(stroke_size*2));
    found_bin[i].lineTo(-stroke_size,-stroke_size);
    }
    }else{
    for(var 
    i=0;i<found_bin.length;i++){
    clearTimeout(timeout)//Found bin currently only has 1 item so cancel the 2 second timeout if available.
    found_bin[i].clear()//Clear the graphics color of the found bin since its size is 1.
    found_bin[i].lineStyle(stroke_size,stroke_color_1);//Change the stroke color back to stroke_color_1 since there is only 1 image selected.
    found_bin[i].moveTo(-stroke_size,-stroke_size);//Draw the stroke rectangle.
    found_bin[i].lineTo(found_bin[i]._width+(stroke_size),-stroke_size);
    found_bin[i].lineTo(found_bin[i]._width-(stroke_size*2),found_bin[i]._height+(stroke_size*1)-(stroke_size*1.5));
    found_bin[i].lineTo(-stroke_size,found_bin[i]._height-(stroke_size*2));
    found_bin[i].lineTo(-stroke_size,-stroke_size);
    }
    }

    }
    onFrame (2) {






        
    MovieClip.prototype.LoadSmoothImage = function(Url,maxW,maxH,redraw) {

            
    this.createEmptyMovieClip("mc",this.getNextHighestDepth());
            
    this.mc.loadMovie(Url);         
                         
            
    this.onEnterFrame = function() {
                
    if(
    this.mc.getBytesTotal()==-1){
    _root.main.images["st"+this._name.split("t")[1]].LoadSmoothImage(file_path2+"0.jpg",100,85,true);//Load it spelled properly.                       
    //_parent[this._name].LoadSmoothImage(file_path2+"0.jpg",100,85,true);//Load it spelled properly.
    this.loaded=false//Set the image to have a local variable called loaded & give it the value: false.
    this.useHandCursor=false//Hide hand cursor if it is not a loaded image.
    }
                  
    if (
    this.mc.getPercentLoaded() == 100) {                  
    this.onRollOver=function(){//On rollover event for current loaded image.
    if(this.line_enabled!=true&&this.loaded!=false){//If this.loaded local variable is not false & this.line_enabled local variable is not true, draw the rectangle for it with stroke_1.
    selected_items[this._name.split("t")[1]]=this//Add this image to the array for selected_items.
    stroke_size=5//Set stroke_size to 5.
    this.lineStyle(stroke_size,stroke_color_1);//Draw the rectangle.
    this.moveTo(-stroke_size,-stroke_size);
    this.lineTo(this._width+(stroke_size),-stroke_size);
    this.lineTo(this._width-(stroke_size*2),this._height+(stroke_size*1)-(stroke_size*1.5));
    this.lineTo(-stroke_size,this._height-(stroke_size*2));
    this.lineTo(-stroke_size,-stroke_size);
    }
    }

    this.onPress=function(){//On press event for the current image.
    if(this.line_enabled==true){//If local_variable for this images line_enabled is true, set it back to false & erase the current rectangle.
    this.line_enabled=false//Set the line back to false.
    this.clear()//Erase the line.
    selected_items[this._name.split("t")[1]]=undefined//Change the array position for this image to equal undefined.
    checkMultiple()//Call function to update all of the rectangles.
    }else{
    this.line_enabled=true//Set this image to line enabled if it wasn't already.
    checkMultiple()//Call function to update all of the rectangles.
    }
    }
    this.onRollOut=function(){//On rollout function for the current image.
    if(this.line_enabled!=true){//On rollout if the images local variable called line_enabled is not true it can be cleared.
    this.clear()//Clear the current rectangle.
    selected_items[this._name.split("t")[1]]=undefined//Set this images array postion to equal undefined for the selected_items array list.
    }
    }
                  
               
                    
    delete this.onEnterFrame 
                    this
    .mc._xscale this.mc._yscale 200;       
                    
    this.ow this.mc._width;
                    
    this.oh this.mc._height;
                    
    this.x_ratio maxW this.ow;
                    
    this.y_ratio maxH this.oh
                    if (
    this.mc._width maxW || this.mc._height maxH) {
                        if ((
    this.x_ratio this.oh) < maxH) {
                            
    this.mc._height Math.ceil(this.x_ratio this.oh);
                            
    this.mc._width this.size._width;
                        } else {
                            
    this.mc._width Math.ceil(this.y_ratio this.ow);
                            
    this.mc._height maxW;
                        }
                    }            
                    if (
    redraw) {
                        
    this.bitmap=new flash.display.BitmapData(this.mc._width,this.mc._heighttrue0xff0000);
                                        
                        
    this.mc.attachBitmap(this.bitmap,this.mc.getNextHighestDepth(),"auto",true);
                        
    this.bitmap.draw(this.mc);      
                        
    this.mc.forceSmoothing false ;      
                        }                    
                    
                    }
                }
            }
            
        
    var 
    file_path:String="students\\3_1\\"
    var file_path2:String="students\\"
    for(var i=1;i<11;i++){
    _root.main.images["st"+i].LoadSmoothImage(file_path+String(i)+".jpg",100,85,true);    
    }
           
                  
        
    stop();

    download v5 (swish)

  16. #16
    Senior Member
    Join Date
    May 2016
    Posts
    451
    i want if 2 images pressed ===>disable other images onRollOver and onPress functions

    you can solve the errors in debug panel

    in line 12

    PHP Code:
    var timeout:Number=
    in line 28

    PHP Code:
    clearTimeout(this.timeout
    in line 41

    PHP Code:
    clearTimeout(this.timeout

    thank you my friend

  17. #17
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hi,

    At the images scripting section there are 2 new arrays:
    PHP Code:
    var all_images:Array=new Array();//This array is for removing images that are not selected if there is more than 1 selected in the checkMultiple() function.
    var images_total:Array=new Array();//Always stores all images. 
    At the images scripting section inside of the checkMultiple() function:
    PHP Code:
    for(var j=0;j<found_bin.length;j++){//If the found bin has more than 1 image inside it we can disable the non selected images.
    for(var i=0;i<all_images.length;i++){
    if(
    found_bin[j]==all_images[i]){//The image was found so it can be removed.
    all_images.splice(i,1)//Splice the found image out.
    }
    }
    }
    for( 
    i=0;i<all_images.length;i++){//Now that the selected images have been separated from the all images array.
    all_images[i].loaded=false//Make all of the images inside of this array a non selectable image.
    all_images[i].useHandCursor=false//Hide the hand cursor.

    At the images scripting section inside of the checkMultiple() function:
    PHP Code:
    for( i=0;i<images_total.length;i++){//Loop through all of the loaded images by checking images_total.length.
    all_images[i]=images_total[i]//If the found_bin's size is less than 2 we can reset the all_images array to have all of the images again.
    images_total[i].loaded=true//Set as a loaded image again making it selectable.
    images_total[i].useHandCursor=true//Show hand cursor again.

    download v6 (swish)
    Last edited by AS3.0; 01-17-2023 at 10:39 AM.

  18. #18
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Removed error from debug panel:

    download v7 (swish)

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