A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: syntax question (varibale in a path)

  1. #1
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755

    syntax question (varibale in a path)

    Im having trouble getting a variable to work in PATH.

    example:

    Code:
    _root.mainContainer.frameContainer.loadMovie(_root.part);
    I want to use a vraible for the "frameContainer" part of the path.

    like:

    Code:
    _root.mainContainer."root.varName".loadMovie(_root.part);

    what am I over looking?..

  2. #2
    I am not an expert
    Join Date
    Aug 2005
    Posts
    175
    what u r missing is the name of the movie u want to load as u specified the target but not the name of the movie.

    loadMovie("name.swf", _root.mymc) // load movie needs 2 arguments

    but u provide only 1 argument

  3. #3
    I am not an expert
    Join Date
    Aug 2005
    Posts
    175
    and also u can't use a string between the path


    _root.mainContainer."root.varName".loadMovie(_root .part); // wrong syntax

    _root.mainContainer.root.varName.loadMovie(_root.p art);

  4. #4
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    not sure what exactly you are trying to do, but here's another suggestion: just assuming that you have several frame containers called frameCont1, frameCont2, frameCont3 ...

    var i = 2; // i holds the number of the container you want to target
    _root.mainContainer["frameCont"+i].loadMovie();
    Please sign here

  5. #5
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Quote Originally Posted by psb
    and also u can't use a string between the path


    _root.mainContainer."root.varName".loadMovie(_root .part); // wrong syntax

    _root.mainContainer.root.varName.loadMovie(_root.p art);
    loadMovie does NOT need to arguments.. it just fine using _root.part for the .swf variable I need to load. loadMovieNum may need two arguments.

    I was using the line of code as an example of what I want to do..I know a string will not work.

    but this doesnt work either:

    _root.mainContainer.root.varName.loadMovie(_root.part);

    anyways..

    its the PATHING part I am having trouble with.

    inside of "mainContainer"...I have several other uniqly named MC's inside of it (all empty container clips)..

    but that part I need to specifically assign by variable determined on _root

    theTick-

    unfortunately..they ARE NOT named sequentially like that.

    so I need a way to pass the variable into the path, and I cant seem to get it to work.

    _root.mainContainer.variableVALUE.loadMoive(_root. part); // get value from _root.

    if I hard code it:
    _root.mainContainer.frameContainer.loadMovie(_root .part);

    it works fine..howver I want to be able to re-use my preloader/transition code... so being able to replace the containerClip INSIDE of mainContainer is a must.

  6. #6
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    ok, why not use eval() ?
    eval("_root.mainContainer."+variableName).loadMovi e();
    that should do it...
    Please sign here

  7. #7
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    theTick-

    because I have never used eval before..or know what it does to use it properly.


    to update, I have tried several things...and got "this" to work:

    Code:
    _root.mainContainer[_root.indiPartContainer].loadMovie(_root.part);
    this is actually loading the movie..like it supposed to.. after trying several variations like:
    Code:
     _root["mainContainer"+"."+_root.indiPartContainer].loadMovie(_root.part);
    &
    Code:
     _root["mainContainer."+_root.indiPartContainer].loadMovie(_root.part);
    but the fisrt ended up working.. however...taking that same syntax..and applying it to where it need to be..is NOT working..

    as in THIS snippet of code (preloader)
    Code:
    onClipEvent (enterFrame) { 
           tb = math.round(_root.mainContainer[_root.indiPartContainer].getBytesTotal()/1024); 
           lb = math.round(_root.mainContainer[_root.indiPartContainer].getBytesLoaded()/1024); 
           if (tb>0 && lb>0) { 
                this.gearsClip_mc.percent_txt.text = math.round((lb/tb)*100); 
                //top(); 
                if (lb>=tb) { 
                     this.gotoAndPlay("fadeOut"); 
                } 
                 
           } 
      }
    it doesnt seem to be working correctly...cause although the external.swf loads..the "preloader' code never displays any % nor does it push the "transition animation" head to the "fadeOut" label...

    I should be checking the SAME containerClip (empty clip) for bytesLoaded as the location where I loadMoive(_root.part); too.

    some reason its NOT checking or returning anything..

  8. #8
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    hi whispers,
    if supplied with a string, eval() turns the string to a reference to that object. e.g.:

    var cont = "frameContainer";
    eval("_root.mainContainer."+cont).loadMovie();

    here the expression in the brackets results in the string "_root.mainContainer.frameContainer" and eval() turns that string into the actual reference.
    if i understand you right, this is what you are looking for...
    Please sign here

  9. #9
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    ok...is there a reason why the way Im posing above wouldnt work though?

    (thanks for the tip by the way...I'll be sure to make use of it)...

    and why the loadMovie(); will work..but NOT the getBtyes/loadedBytes part?

    thanks.. I'll try to convert all to use the eval() function

  10. #10
    Senior Member
    Join Date
    Oct 2003
    Posts
    1,354
    Make sure to use a capital 'M' for Math.round();
    Also if testing local, everything gets loaded in one big chunk, so bytes total and loaded are always going to be the same.

  11. #11
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    Like mentioned above, make sure your testing in an online environment. The code format looks correct. Make sure the clip holding the code sample doesn't have another enterframe event applied with AS somewhere. Maybe create a preload function with setInterval instead to keep objects open for enterframe events.........

    code:

    function myPreloader(targetClip) {
    createEmptyMovieClip("holder", 9999);
    centerX = Stage.width/2;
    centerY = Stage.height/2;
    holder.createTextField("display", 100, centerX, centerY, 40, 20);
    holder.display.border = true;
    holder.display.background = true;
    function checkLoad() {
    total = int(_root.targetClip.getBytesTotal());
    download = int(_root.targetClip.getBytesLoaded());
    percent = int(download/total*100)+"%";
    _root.holder.display.text = percent;
    if (total == download) {
    _root.holder.unloadMovie();
    clearInterval(myLoadCheck);
    }
    }
    myLoadCheck = setInterval(checkLoad, 10);
    }
    //Usage..... function name(mcInstanceName);
    myPreloader(_root.imageHolder);


  12. #12
    Senior Member random25's Avatar
    Join Date
    Apr 2002
    Posts
    566
    think i know what you mean whispers, and i had a similar problem
    this is a peice of what i ended up with:
    Code:
    if(_root.loading.text !=""){
    totalBytes =  _root[_root.loading.text].getBytesTotal()
    loadedBytes = _root[_root.loading.text].getBytesLoaded()
    }else{
    totalBytes =  _root.getBytesTotal()
    loadedBytes = _root.getBytesLoaded()
    	}
    this works correctly for me.

    I also made an empty dynamic text field at the root of the movie with the variable loading to hold the value as text

    This way the variable is "" by default when the site first loads, so the preloaded will work for the main .swf as well as for external files.

    You also need to add script to your buttons to set this variable to the path of the movie clip the external file is being loaded into.
    Last edited by random25; 03-01-2006 at 02:29 AM.

    If you want to make an apple pie from scratch, you must first create the universe. Carl Sagan

  13. #13
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    hhmm

    ok..

    I tried to use this:
    Code:
    onClipEvent (enterFrame) {
    	tb = Math.round(_root.mainContainer[_root.indiPartContainer].getBytesTotal()/1024);
    	lb = Math.round(_root.mainContainer[_root.indiPartContainer].getBytesLoaded()/1024);
    	if (tb>0 && lb>0) {
    		this.gearsClip_mc.percent_txt.text = math.round((lb/tb)*100);
    		this.stop();
    		if (lb>=tb) {
    			this.gotoAndPlay("fadeOut");
    		}
    		
    	}
    }
    changed the math to Math.. still no go.. not sure what I see different in random25's code than in mine?/ anyone?


    Im going to try and convert to eval(); now..

    if all else fails...I'll try to convert the whole thing to a function as NTD suggests..

  14. #14
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    ok..it HAS to be somethign in the preloader part..

    if I use the eval or the original way..the .swf LOADS fine..its the "prelaoder" check that moves the transition clip forward...or the perctanges showing that is NOT working...

    Code:
    onClipEvent (enterFrame) {
    	tb = Math.round(eval("_root.mainContainer."+_root.indiPartContainer).getBytesTotal()/1024);
    	lb = Math.round(eval("_root.mainContainer."+_root.indiPartContainer).getBytesLoaded()/1024);
    	if (tb>0 && lb>0) {
    		this.gearsClip_mc.percent_txt.text = Math.round((lb/tb)*100);
    		this.stop();
    		if (lb>=tb) {
    			this.gotoAndPlay("fadeOut");
    		}
    	}
    }

  15. #15
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    just to update: (and Im not really sure WHY its working.)

    I did this..and it works fine.. I did NOT change any syntax...just changed some frame code to be object code...and took my original object code and put it inside the movieClip on frame 1.

    so the original frame code is now:
    Code:
    onClipEvent (load) {
    	_root.mainContainer[_root.indiPartContainer].loadMovie(_root.part);
    	trace(_root.indiPartContainer);
    	trace(_root.part);
    }
    and my original object code switched to be frame code INSIDE the clip:
    Code:
    this.onEnterFrame = function() {
    	tb = Math.round(eval("_root.mainContainer."+_root.indiPartContainer).getBytesTotal()/1024);
    	lb = Math.round(eval("_root.mainContainer."+_root.indiPartContainer).getBytesLoaded()/1024);
    	if (tb>0 && lb>0) {
    		this.percent_txt.text = Math.round((lb/tb)*100);
    		this.stop();
    		if (lb>=tb) {
    			_parent.gotoAndPlay("fadeOut");
    		}
    	}
    }
    I NOW see everything...the percentage%...the transition...and it comeplets when fully loaded. (wierd)

  16. #16
    Senior Member random25's Avatar
    Join Date
    Apr 2002
    Posts
    566
    Yes, weird indeed.
    Glad you got it working though

    If you want to make an apple pie from scratch, you must first create the universe. Carl Sagan

  17. #17

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