A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Scope & moviecliploader problems

  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    17

    [F8] Scope & moviecliploader problems

    I'm making some sort of xml gallery. Here's part of the loop that builds the thumbnails

    Code:
    for (var i = 0; i<node_xml.childNodes.length; i++) {
    		curr_item = curr_menu.attachMovie("menuitem", "item"+i+"_mc", i);
    ...
    Here's the problem. Inside the above loop, I have the following code: I'm using the movieClipLoader class to preload each thumbnail and the progress is shown inside each thumbnail mc.

    Code:
    // Load in thumbnails
    		var mcl:MovieClipLoader = this["mcl"+i];
    		mcl = new MovieClipLoader();
    		var mclL:Object = this["mclL"+i];
    		mclL = new Object();
    		mclL.onLoadProgress = function(target,loaded,total) {
    			curr_item.menuitem_label.text = Math.round((loaded/total)*100);
    			curr_item.loading._visible = true;
    		}
    		mclL.onLoadInit = function() {
    			curr_item.menuitem_label.text = curr_item.gid;
    			curr_item.loading._visible = false;
    		}
    Is this the correct way to assign unique instance names to each MovieClipLoader object?
    I'm having problems displaying the gid value in the textfields because of scope problems. Not sure what to do. I read up on the Delegate class but it's for functions.

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    Hi,

    At least here, the addListener is missing from your code. But so is the loadClip()...
    code:

    mcl.addListener(mclL)



    For example, this works just fine:
    code:

    for (var i = 1; i <= 5; i++)
    {
    var mc = this.createEmptyMovieClip("mc" + i, i);
    mc._x = 50 * i;
    var mcl:MovieClipLoader = this["mcl" + i];
    mcl = new MovieClipLoader();
    var mclL:Object = this["mclL" + i];
    mclL = new Object();
    mclL.onLoadProgress = function(target, loaded, total)
    {
    trace("onProgress " + target);
    };
    mclL.onLoadInit = function(target)
    {
    trace("onLoadInit " + target);
    };
    mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", mc);
    mcl.addListener(mclL)
    }



    But it has a problem. I'd create the objects like this instead:
    code:

    var mcl:MovieClipLoader = this["mcl" + i] = new MovieClipLoader();
    var mclL:Object = this["mclL" + i] = new Object();



    Because something like
    code:

    var mcl:MovieClipLoader = this["mcl" + i];


    is useless, as this["mcl" + i] is undefined.
    code:

    var mcl:MovieClipLoader = this["mcl" + i];
    mcl = new MovieClipLoader();
    trace(this["mcl" + i]); // undefined


    while
    code:

    var mcl:MovieClipLoader = this["mcl" + i] = new MovieClipLoader();
    trace(this["mcl" + i]); // [object Object]


  3. #3
    Junior Member
    Join Date
    May 2006
    Posts
    17
    Hey thanks! I'll try that out.

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