A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Dynamic Variables in Functions

  1. #1
    Senior Member
    Join Date
    Aug 2001
    Posts
    128

    Dynamic Variables in Functions

    (am using Flash 8)

    On my stage I have 3 movies, M1, M2 and M3 and a dynamic text box set to show the variable 'txt'.

    On my 1st frame I have the actionscript:

    Code:
    for (j=1; j<=3; j++){
    	
    	_root["m"+j].onPress=function(){ 
    	_root.txt=j;
    	}
    	
    }
    What I want to be able to do is to display either the number 1, 2 or 3 DYNAMICALLY in the text box depending on whether M1, M2, or M3 was selected.

    The code above will always show '4' in the text box nomatter which movie is selected. (due to the function obviously being called after for loop has finished)

    How do I resolve/rewrite this please (it is imperitive that M1-M3 are kept as movie symbols)?

    (please note that what I have done here is very a very simlified version of what I am tring to do, however if someone can solve this problem for me, then I can apply the result to my more complex project. Thanks)

    Cheers! (P.S an example .fla FLash 8 file is enclosed).
    Attached Files Attached Files
    [swf width="300" height="40" background="#000000"]http://www.zizunetwork.com/zizunetworkcouk.swf[/swf]

  2. #2
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    for (j=1; j<=3; j++){

    _root["m"+j].onPress=function(){
    _root.mytextfield.text =j;
    }

    }

    try that

    edit:
    actually try this

    Code:
    for (j=1; j<=3; j++){
    	root["m"+j].msg = j
    	_root["m"+j].onPress=function(){ 
    	_root.mytextfield.text =this.msg;
    	}
    	
    }
    or something like that should work
    Last edited by joran420; 12-05-2006 at 02:09 PM.

  3. #3
    Senior Member
    Join Date
    Aug 2001
    Posts
    128
    [swf width="300" height="40" background="#000000"]http://www.zizunetwork.com/zizunetworkcouk.swf[/swf]

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