dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Quick string question

  1. #1
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521

    Quick string question

    Can anyone tell me why the first var works, but the second doesn't!?

    var formPath:String = "form";
    var formPath:String = "contents.form";
    _level0[formPath].message = formPath;


    _level0.contents.form.message and _level0.form.message do exist, but for some reason, the string doesn't like . characters!?

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    split formPath to an array and use array notation to build the path -

    var formPath:String = "contents.form";
    var arr:Array = formPath.split(".");
    _level0[arr[0]][arr[1]].message = formPath;

  3. #3
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521
    The problem with that, is that it will only work for either the single level, or double level reference. Not both.

    The reason I want it to work for both, is that I plan to load the script into a parent movie, thus I plan to pass a different root reference depending on whether the script is run independently or as a child.

    Any other suggestions?

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    check the array length within an if(condition)

    PHP Code:
    var formPath:String "form";
    //var formPath:String = "contents.form";

    var arr:Array = formPath.split(".");

    if(
    arr.length>1){
    _level0[arr[0]][arr[1]].message formPath;
    } else {
    _level0[arr[0]].message formPath;


  5. #5
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521
    Thanks a_modified_dog

    Somebody showed me a more elegant method of what I was trying, using MovieClip instead of String:

    var formPath:MovieClip = _level0.form;
    var formPath:MovieClip = _level0.contents.form;
    formPath.message = formPath;

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