A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: [CS3][AS2] My code only works after a page reload in firefox 3

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    19

    [CS3][AS2] My code only works after a page reload in firefox 3

    I have a big problem.

    I'm using Flash CS3, exporting for flash player 9 and having troubles with the code below only in Firefox 3 (flash player 9 or 10)

    In IE 6 & 7, all works OK.

    The code below should show small thumbnails of images. It does work on everything I tested except firefox 3. What is weird is that if I empty my cache and load the page online, it does not show any thumbnails or sometimes only one. However, if i reload the page without emptying my cache, it will then work perfectly.

    Here is my code :

    Code:
    System.security.allowDomain("http://www.translucidedesign.com");
    var prefix = 'http://www.translucidedesign.com/kana/';
    
    //1. Import base class
    import mx.utils.Delegate;
    
    //2. XMLLoader setup
    var XMLLoader:XML;
    XMLLoader = new XML();
    XMLLoader.ignoreWhite = true;
    XMLLoader.onLoad = Delegate.create(this,onObjectsLoaded);
    XMLLoader.load(prefix+'domainebrossard.xml');
    
    function onObjectsLoaded(success:Boolean) {
    	if (success) {
    		var nodes:Array = this.XMLLoader.childNodes[0].childNodes;
    		var currentx = 10;
    		var currenty = 10;
    		var itemsxy = 76;
    		var spacing = 10;
    		var pictures:Array = new Array();
    		var thumb = '';
    		var picture = '';
    		
    		for (var i:Number = 0; i<nodes.length; i++) {
    			thumb = nodes[i].attributes.thumb;
    			picture = nodes[i].attributes.image;
    			
    			var thisObj:Object = new Object();
    			thisObj.pic = picture;
    			pictures[i] = thisObj;
    			//trace(picture);
    			attachMovie('photosquare','picturethumb'+i,this.getNextHighestDepth());
    			var thisPic = eval('picturethumb'+i);
    			thisPic._x = currentx + (i%4)*(itemsxy+spacing);
    			thisPic._y = currenty + (itemsxy+spacing)*Math.floor(i/4);
    			
    			//Movie clip loader for pictures...
    			var mcLoader = new MovieClipLoader();
    			var mclListener:Object = new Object();
    			mclListener.itemsxy = itemsxy;
    			mclListener.onLoadInit = function(mc:MovieClip) {
    				mc._x = 0;
    				mc._y = 0;
    				mc._width = this.itemsxy;
    				mc._height = this.itemsxy;
    				trace(mc+' has received onloadinit! -> '+mc._url+', x='+mc._x+', y='+mc._y);			
    			}
    			mcLoader.addListener(mclListener);
    			mcLoader.loadClip(prefix+thumb, thisPic.pic);
    
    			thisPic.btn.number = i;
    			thisPic.btn.onPress = function() {
    				if (_root.popup)_root.popup.removeMovieClip();
    				_root.attachMovie('popup','popup',_root.getNextHighestDepth());
    				_root.popup.number = this.number;
    				_root.popup.loadPic(this.number);
    				_root.popup._x = 200;
    				_root.popup._y = 200;
    			}
    		}
    		//trace('pictures : '+ pictures[0].pic);
    		_root.pictures = pictures;
    	} else {
    		trace('Error reading XML');
    	}
    }

    Here is my XML file :

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    
    <xmldata>
    
    <pic thumb="gallery/thumb_001.jpg" image="gallery/001.jpg"></pic>
    
    <pic thumb="gallery/thumb_01.jpg" image="gallery/01.jpg"></pic>
    
    <pic thumb="gallery/thumb_002.jpg" image="gallery/002.jpg"></pic>
    
    <pic thumb="gallery/thumb_003.jpg" image="gallery/003.jpg"></pic>
    
    <pic thumb="gallery/thumb_004.jpg" image="gallery/004.jpg"></pic>
    
    <pic thumb="gallery/thumb_04.jpg" image="gallery/04.jpg"></pic>
    
    <pic thumb="gallery/thumb_005.jpg" image="gallery/005.jpg"></pic>
    
    <pic thumb="gallery/thumb_006.jpg" image="gallery/006.jpg"></pic>
    
    <pic thumb="gallery/thumb_007.jpg" image="gallery/007.jpg"></pic>
    
    <pic thumb="gallery/thumb_08.jpg" image="gallery/08.jpg"></pic>
    
    <pic thumb="gallery/thumb_09.jpg" image="gallery/09.jpg"></pic>
    
    <pic thumb="gallery/thumb_10.jpg" image="gallery/10.jpg"></pic>
    
    <pic thumb="gallery/thumb_11.jpg" image="gallery/11.jpg"></pic>
    
    <pic thumb="gallery/thumb_12.jpg" image="gallery/12.jpg"></pic>
    
    <pic thumb="gallery/thumb_013.jpg" image="gallery/013.jpg"></pic>
    
    <pic thumb="gallery/thumb_15.jpg" image="gallery/15.jpg"></pic>
    
    <pic thumb="gallery/thumb_16.jpg" image="gallery/16.jpg"></pic>
    
    <pic thumb="gallery/thumb_17.jpg" image="gallery/17.jpg"></pic>
    
    <pic thumb="gallery/thumb_18.jpg" image="gallery/18.jpg"></pic>
    
    <pic thumb="gallery/thumb_19.jpg" image="gallery/19.jpg"></pic>
    
    <pic thumb="gallery/thumb_20.jpg" image="gallery/20.jpg"></pic>
    
    </xmldata>
    Anybody have an idea?

  2. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    Anybody have a clue?

  3. #3
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    does the swf itself have a preloader?

  4. #4
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    no preloader.

  5. #5
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    In fact the original file has a preloader but I made new file to isolate the problem and the code i posted in the only thing in the file...and it still do the same bug.

  6. #6
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    Did anybody found anything wrong in this code?

  7. #7
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    Nothing new ?

  8. #8
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    please help !

  9. #9
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    annoying bumper- unsubscribed!

  10. #10
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    Quote Originally Posted by renderhjs
    annoying bumper- unsubscribed!
    Sorry to bump like this but i really need an answer,

    I tried every possible way to do that but it just don't work in FF3...

    I tried using MovieClipLoader, or loadMovie both produce the same problem so the problem must lie somewhere else.. i tried this code online on 2 different servers and both produce the same problem... however in offline mode or on my test server (lochalost) it works even on FF3... so I still got no idea where the problem comes from...

    Ive done this many times in the past and never had a problem... this is just so stupid... i havent found any answer yet to this problem...

  11. #11
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    did you set allowscriptaccess to true in the html? Try a relative path to the xml file instead of absolute? If it works locally and not remotely it's probably a security thing that FF doesnt allow.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  12. #12
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    allowscriptaccess was set to sameDomain, I changed it to true, but the same bug happened....

    I tried a relative path or absolute way before posting this to the forum...believe me it dont change anything... it works the same way and always bug on the first load on FF3...

    So... any other suggestions ? The weird thins is I loaded pictures with an XML file many times and never had a weird bug like this...

    I isolaed the code I posted in a standalone file to see it it was my code or the website in which the code is... result : the code is buggy in itself or there is a bug in the flash lugin for FF3 or im missing something I<m not aware of yet...

    Thought... you are right... it definitively seems like a security feature that blocks my code on the first load...

    What is weird is that on the first load, the XML is loaded properly because when I click on a picture (even if the thumbnail is not loaded, the picture pops-up and its the right picture... so the data part is fully loaded and working even in the first load in FF3, it generates empty thumbnails and the right number of them, there is just the thumbnails that are not loaded... so how can I load them properly...I don't know anything else apart loadMovie and MovieClipLoader...

  13. #13
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    When the bug happens, I see it tries loading the thumbnails in FF3 cause there is written in the status bar at the bottom

    Transferring from blablabla...

    But it just seems to give up anytime soon after that... in IE however the thumbnails appears one after the other in the order they are loaded and it dont just "give up" like this...

    Im thinking that maybe its related to the way flash considers variables... they are all pointers by default... ill try searching in that area tonight...

    What could also solve my problem is to redesign the code into 2 loops, the first to parse the XML and the second to run through the parsed XML contained in an array to load the thumbnails... maybe that would help... I know that each time I had a weird bug... rewriting code always gives good chances to mistakenly create a workaround... what I hate about this is that we still dont know the source of the problem and well still loose many hours the next time this happens...

  14. #14
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    Well, regardless if this helps take the mcLoader out of the loop, what a waste:

    PHP Code:
    System.security.allowDomain("http://www.translucidedesign.com");
    var 
    prefix 'http://www.translucidedesign.com/kana/';

    //1. Import base class
    import mx.utils.Delegate;

    //2. XMLLoader setup
    var XMLLoader:XML;
    XMLLoader = new XML();
    XMLLoader.ignoreWhite true;
    XMLLoader.onLoad Delegate.create(this,onObjectsLoaded);
    XMLLoader.load(prefix+'domainebrossard.xml');

    var 
    mcLoader = new MovieClipLoader();
    var 
    mclListener:Object = {};
    mcLoader.addListener(mclListener);
    mclListener.onLoadInit mcLoaded;

    function 
    onObjectsLoaded(success:Boolean) {
        if (
    success) {
            var 
    nodes:Array = this.XMLLoader.childNodes[0].childNodes;
            var 
    currentx 10;
            var 
    currenty 10;
            var 
    itemsxy 76;
            var 
    spacing 10;
            var 
    pictures:Array = new Array();
            var 
    thumb '';
            var 
    picture '';
            
            for (var 
    i:Number 0i<nodes.lengthi++) {
                
    thumb nodes[i].attributes.thumb;
                
    picture nodes[i].attributes.image;
                
                var 
    thisObj:Object = new Object();
                
    thisObj.pic picture;
                
    pictures[i] = thisObj;
                
    //trace(picture);
                
    attachMovie('photosquare','picturethumb'+i,this.getNextHighestDepth());
                var 
    thisPic = eval('picturethumb'+i);
                
    thisPic._x currentx + (i%4)*(itemsxy+spacing);
                
    thisPic._y currenty + (itemsxy+spacing)*Math.floor(i/4);
                
                
    //Movie clip loader for pictures...
                
    mc.itemsxy itemsxy;
                
    mcLoader.loadClip(prefix+thumbthisPic.pic);
                
    thisPic.btn.number i;
                
                
    thisPic.btn.onPress = function() {
                    if (
    _root.popup)_root.popup.removeMovieClip();
                    
    _root.attachMovie('popup','popup',_root.getNextHighestDepth());
                    
    _root.popup.number this.number;
                    
    _root.popup.loadPic(this.number);
                    
    _root.popup._x 200;
                    
    _root.popup._y 200;
                }
            }
            
    //trace('pictures : '+ pictures[0].pic);
            
    _root.pictures pictures;
        } else {
            
    trace('Error reading XML');
        }
    }

    function 
    mcLoaded(mc:MovieClip){
        
    mc._x 0;
        
    mc._y 0;
        
    mc._width mc.itemsxy;
        
    mc._height mc.itemsxy;    

    I didn't check it but this should function fine although I don't know that it will fix your problem. The code is fairly clean above otherwise so I don't know what could cause it and you should be capable of debugging this if you wrote that.

    I believe onLoadInit fires in the scope of the mc so passing mc:MovieClip as a parameter is unnecessary? I forget. Good luck
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  15. #15
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    PHP Code:
    System.security.allowDomain("http://www.translucidedesign.com");
    var 
    prefix 'http://www.translucidedesign.com/kana/';

    //1. Import base class
    import mx.utils.Delegate;

    //2. XMLLoader setup
    var XMLLoader:XML;
    XMLLoader = new XML();
    XMLLoader.ignoreWhite true;
    XMLLoader.onLoad Delegate.create(this,onObjectsLoaded);
    XMLLoader.load(prefix+'domainebrossard.xml');

    var 
    mcLoader = new MovieClipLoader();
    var 
    mclListener:Object = {};
    mcLoader.addListener(mclListener);
    mclListener.onLoadInit mcLoaded;

    function 
    onObjectsLoaded(success:Boolean) {
        if (
    success) {
            var 
    nodes:Array = this.XMLLoader.childNodes[0].childNodes;
            var 
    currentx 10;
            var 
    currenty 10;
            var 
    itemsxy 76;
            var 
    spacing 10;
            var 
    pictures:Array = new Array();
            var 
    thumb '';
            var 
    picture '';
            
            var 
    num:Number nodes.length;//declare outside of the loop otherwise you have to count nodes each time
            
    var i:Number 0;//declare it here too.
            
    for (; i<numi++) {
                
    thumb nodes[i].attributes.thumb;
                
    picture nodes[i].attributes.image;
                
                var 
    thisObj:Object = {};//faster than new Object();
                
    thisObj.pic picture;
                
    pictures.push(thisObj);//push is faster than straight equality
                //trace(picture);
                
    var thisPic:MovieClip attachMovie('photosquare','picturethumb'+i,this.getNextHighestDepth());//attachMovie returns the attached movies name if you use it right.
                
                
    thisPic._x currentx + (i%4)*(itemsxy+spacing);
                
    thisPic._y currenty + (itemsxy+spacing)*Math.floor(i/4);
                
                
    //Movie clip loader for pictures...
                
    mc.itemsxy itemsxy;
                
    mcLoader.loadClip(prefix+thumbthisPic.pic);
                
    thisPic.btn.number i;
                
                
    thisPic.btn.onPress thisPicBtnPress;
            }
            
    //trace('pictures : '+ pictures[0].pic);
            
    _root.pictures pictures;
        } else {
            
    trace('Error reading XML');
        }
    }

    function 
    mcLoaded(mc:MovieClip){
        
    mc._x 0;
        
    mc._y 0;
        
    mc._width mc.itemsxy;
        
    mc._height mc.itemsxy;    
    }

    function 
    thisPicBtnPress(){
            if (
    _root.popup)_root.popup.removeMovieClip();
            
    _root.attachMovie('popup','popup',_root.getNextHighestDepth());
            
    _root.popup.number this.number;
            
    _root.popup.loadPic(this.number);
            
    _root.popup._x 200;
            
    _root.popup._y 200;


    Here. a little faster/ different/ cleaner.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  16. #16
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    Thank you for this code.... its definitively faster that way...

    But unfortunately it didn't solve the problem...

  17. #17
    Junior Member
    Join Date
    Jan 2009
    Posts
    19
    I finally solved this weird bug by adding the gallery loading code at 2 places in the same FLA so its basically loading the jpegs twice so for Firefox, when its time to see the thumbnails, its the second time they are loaded which solves this bug the nasty way...

    I'm still curious and would like to know what is causing this bug...but I don't have the time to work on that...

    Feel free to post another solution here if you found the bug...

    Ill be coming around from time to time to see if someone found the bug...

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