views:

89

answers:

2

I have a gallery where it will load an image after a previous image is loaded, so every time 'i' will +1 so that it could move to the next image. This code works fine on my other files, but I dunno why it doesn't work for the current file.

Normally if I trace 'i' the correct will be

0,1,2,3,4,5,6... etc

adding on till the limit, but this files its 'i' repeat the 1st number twice, only it continues to add

0,0,1,2,3,4,5,6...etc

The code is completely the same with the other file I'm using, but I don't know why it just doesn't work here. The code does not seems to have any problem. Anyway i can work around this situation?

private var i:uint=0;

private function loadItem():void {

        if (i<myXMLList.length()) {
            loadedPic=myXMLList[i].thumbnails;

            galleryLoader = new Loader();
            galleryLoader.load(new URLRequest(loadedPic));
            galleryLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,picLoaded);
        } else {
            adjustImage();
        }
    }

    private function picLoaded(event:Event):void {
        var bmp=new Bitmap(event.target.content.bitmapData);
        bmp.smoothing=true;
        bmpArray.push(bmp);
        imagesArray[i].addChild(bmp);

        i++;
        loadItem();
    }
+1  A: 

That code looks fine, it's really very difficult to tell what might be causing that. The best advice I can give you would be to set some break points; for example set one at the point where you add the event listener to the galleryLoader object, and then run Flash's debugger. You run it by going to Debug > Debug Movie.

The debugger will stop at that line, and you will be able to look in the Variables window to see your i variable as you step through the code line-by-line. You step through by pressing the step in button, inside the Debug Console window. I've put in an image below showing the debugger's specific windows (that you won't see at any other time in Flash):

alt text

I think that by doing that (if you haven't already tried, that is) you should pretty quickly see what's going wrong. Hope it helps anyway.

debu

debu
basically it does not show any error at all :(
Hwang
Yeah, that's why you should use the debugger. Your program isn't doing anything illegal, so to speak, so there's no error. You just need to follow the execution of your code to see what happens to your *i* variable at what point. If you want, you can upload the .fla somewhere and I'll have a look.
debu
A: 

I've finally found out whats the problem.

public function grid():void {
        addEventListener(Event.ADDED_TO_STAGE, add2Stage);
    }

    private function add2Stage(event:Event):void {
        myLoader=new URLLoader();
        myLoader.load(new URLRequest(galleryXML));
        myLoader.addEventListener(Event.COMPLETE,processXML);
    }

Its because I'm using adding the functions to stage. After I remove the add2stage function then everything's fine. But why will it affect and run the function twice at 1st? I'm just adding it to the stage to get the stage width.

Hwang