A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: eval(stringVar+var) question

  1. #1
    Junior Member
    Join Date
    Jun 2002
    Posts
    9
    Hej, If I have a string variable named newName and a variable name count, can I get a mc path by doing this:

    frameC = eval(newName+count);

    ? please anser me this time I need your help aswell. Thank you for your time.

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    667
    It should. If it's not working try adding in a trace to see what you are geting.

  3. #3
    Maya * ActionScript Addict DangerAhead's Avatar
    Join Date
    Jun 2000
    Location
    San Francisco
    Posts
    299

    YOU DON'T NEED EVAL

    eval is deprecated. meaning it won't be around long.
    but you don't need it.

    Code:
    frameC = "" + newName + count; // this will concatenate the two into a string
    
    frameC = newName add count; // same
    
    
    SO..... 
    
    
     MC.gotoAndPlay("" + newName + count);
     MC.gotoAndPlay(newName add count);
    
    will both work

  4. #4
    Senior Member
    Join Date
    Nov 2001
    Posts
    667

    Re: YOU DON'T NEED EVAL

    Originally posted by DangerAhead
    eval is deprecated. meaning it won't be around long.
    but you don't need it.
    Actualy eval is NOT deprecated, although it doesn't work the same in F5 and FMX.

    Although you don't need eval for what he is doing, what you suggest will not work.

    The difference:

    piece3 = "dangerous";
    x = 3;
    trace("piece" + x); // Output: peice3
    trace(eval("piece" + x)); // Output: dangerous

    And just as a point of intrest, add IS deprecated.

  5. #5
    Junior Member
    Join Date
    Jun 2002
    Posts
    9

    ...wait a minut

    Maybe I didnt made myself clear. frameC is a MOvieClip INSTANCE. Are you guys sure that I dont need eval?This is the code Im using:

    _root.dupli = function(frameSpace,newName) {
    var i = 0;
    while (i<700) {
    duplicateMovieClip(_root.timeLine.frameClip1.theFr ame,newName+i, i);

    var frameC = eval("/timeLine/frameClip1/"+newName+i);

    frameC._x = i;
    frameC.onEnterFrame=function(){
    frameC.makeMeHappy(i);
    }
    i+=frameSpace;
    }
    };



    By the way, dangerahead, Im not using 'add' and I dont see what 'add' has to do with 'eval' being deprecated although its not, thanks for your time and for replying anyway.



  6. #6
    Maya * ActionScript Addict DangerAhead's Avatar
    Join Date
    Jun 2000
    Location
    San Francisco
    Posts
    299

    My method works!

    first of all, etcettera, my code works. Try it yourself.

    Second of all:

    Code:
    _root.dupli = function(frameSpace, newName) {
    	var i = 0;
    	while (i < 700) {
    		duplicateMovieClip(_root.timeLine.frameClip1.theFrame, newName + i, i);
    		frameC = newName + i;
    		_root.timeline.frameClip1[frameC]._x = i;
    		_root.timeline.frameClip1[frameC].onEnterFrame = function() {
    			_root.timeline.frameClip1[frameC].makeMeHappy(i);
    		};
    		i += frameSpace;
    	}
    };

    you're welcome, Sugar.
    [Edited by DangerAhead on 06-26-2002 at 09:08 PM]

  7. #7
    Senior Member
    Join Date
    Nov 2001
    Posts
    667
    First of all:

    I'm not saying your code won't work, I said it wasn't what he was asking for. Your code returns a string, and although a string can be used to make a refrence to an MC, it is not in itself a refrence to one.

    Second of all:

    Code:
    _root.dupli = function(frameSpace,newName) { 
    	for (var i=0;i<700;i+=framespace) {
    		duplicateMovieClip(_root.timeLine.frameClip1.theFrame,newName+i, i);
    		var frameC = _root["timeLine.frameClip1."+(newName+i)]; 
    		frameC._x = i; 
    		frameC.onEnterFrame=function(){ 
    			frameC.makeMeHappy(i); 
    		}
    	} 
    };
    
    or 
    
    _root.dupli = function(frameSpace,newName) { 
    	for (var i=0;i<700;i+=framespace) {
    		duplicateMovieClip(_root.timeLine.frameClip1.theFrame,newName+i, i);
    		var frameC = eval("timeLine.frameClip1."+(newName+i)); 
    		frameC._x = i; 
    		frameC.onEnterFrame=function(){ 
    			frameC.makeMeHappy(i); 
    		}
    	} 
    };
    Eval or no eval, whatever floats your boat.

  8. #8
    Senior Member
    Join Date
    Sep 2001
    Posts
    178
    Hi,
    Actually, there is an even easier way to do what you are trying to do, because duplicateMovieClip now returns a reference to the clip it creates. Use this:

    Code:
    _root.dupli = function(frameSpace,newName) { 
    	for (var i=0;i<700;i+=framespace) {
    		var myClip = _root.duplicateMovieClip(_root.timeLine.frameClip1.theFrame,newName+i, i);
    		myClip._x = i; 
    		myClip.onEnterFrame=function(){ 
    			this.makeMeHappy(i); 
    		}
    	} 
    };
    This way you do not need to use eval or the [] notation. Chuckles8421

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