A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Variable as movieClip name?

  1. #1

    Post Variable as movieClip name?

    Timeline 10:
    I assign the variable "company" a value:
    company = ford;

    Timeline 20:
    I have a button with the following script that needs to access a movieClip called "ford" (also located at timeline number 20):
    on (press) {
    company.gotoAndPlay(2);
    }

    The variable doesn't get passed. I have tried tracing it with:
    trace(company);
    trace(typeof(company));

    In both instances I get "undefined" back.

    When I insert "company = ford;" directly in the button so it looks like this...
    on (press) {
    company = ford;
    company.gotoAndPlay(2);
    }
    ... it works, and my traces gives me:
    _level0.instance1.ford
    movieclip

    I tried replacing "company = ford;" with "_global.company = ford;" at timeline 10, but still no luck.

    Any good ideas on how I can assign "ford" to a variable early on the timeline and then use the variable as a movieClip name later?

    Thanks in advance!
    :: serviator

  2. #2
    Danny Gomez Creations ® cosmiceye's Avatar
    Join Date
    Mar 2002
    Location
    under a palmtree in Jamaica waiting for psytopia 2005 to begin
    Posts
    982

    //timeline 10:
    var company=_level0.instance1.ford;

    //but if you name your "instance1", it should work for sure

    var company=_root.myMc.ford;

  3. #3
    Thank you Cosmiceye - I did try both your suggestions though and I still get "undefined" in my traces and it's not going to the movieClip.

  4. #4
    Junior Member
    Join Date
    Jun 2001
    Posts
    14

    Eval Command

    Look up the eval() command in the AS dictionary - it's your solution.

    Ex. newMovie = eval(company);
    newMovie.gotoAndPlay(2);

    or somethig like that.

  5. #5
    I tried the eval() function and it works fine if I use it locally as your example shows:
    newMovie = eval(company);
    newMovie.gotoAndPlay(2);

    But if I have "newMovie = eval(company);" at timeline 10 and "newMovie.gotoAndPlay(2);" at timeline 20, the variable is not being passed. In Director I was able to make variables global and I thought I could do that in Flash too (I tried the _global command in Flash, but no luck).

    What could I be doing wrong?

  6. #6
    Senior Member
    Join Date
    Jul 2001
    Location
    Planet Earth
    Posts
    298
    Worked for me, must be something funky going on. I did exactly what you said and it worked.

  7. #7
    well if this hasent been said this will work for sure:

    this[company].gotoAndStop(1)

    it can also work like:

    _root[company+x].gotoAndStop(1)
    _parent["company"+x].gotoAndStop(1)

    Hope this makes sense. Whats inside the brackets is evaluated and put out as the text (variable or mc) that it evals to

  8. #8
    Junior Member
    Join Date
    Jun 2001
    Posts
    14

    eval()


    Originally posted by serviator
    But if I have "newMovie = eval(company);" at timeline 10 and "newMovie.gotoAndPlay(2);" at timeline 20, the variable is not being passed.
    What could I be doing wrong? [/B]
    But why would you put the eval command one place and the control code elsewhere? If you need to have the gotoAndPlay on frame 20, put the "newMovie = eval(company)" in the same frame with the rest of the code.
    Oh yeah, you might also need to write it as "newMovie = eval("_root."+company);" Sometimes that makes a difference.

  9. #9
    I am not sure eval() is the right command to use, but what I am doing is having a button inside a movieClip, and I want to use this movieclip for different sections (and locations on the timeline). So if I am at timeline 10 I set the variable company = ford and the button script will look like this:

    on (press) {
    company.gotoAndPlay(12);
    }

    at timeline 20 the variable company = nissan

    and the above mentioned button will react differently.

    It must be possible to have movieClip names as global variables?!

    Thanks


    [Edited by serviator on 05-28-2002 at 05:29 PM]

  10. #10
    I created a sourcefile. It is located at http://www.serviator.dk/variable.fla .

    If anyone can the button to work, I'd be very happy!

  11. #11
    gskinner.com
    Join Date
    Feb 2002
    Location
    N.America
    Posts
    455
    Sounds like your problem is that you are creating the variable on the _root, but trying to reference it inside a movieClip.

    Try this:

    on Frame 10:
    company = ford;

    on the button inside the MC:
    _root.company.gotoAndPlay(12);
    trace(_root.company) // see if it is undefined.

    That should work.
    ZE.

  12. #12
    With all of you guys help, I finally got everything working. The button is working with 3 different variables and can easily be customized.

    Well, piece of cake for the hardcore coders here, but a great goal accomplished for a more designer oriented guy like me... Anyway, thanks a bunch!

    Feel free to stop by and see my new website coming up - hopefully - in a month or less (right now, it's a 2 year old design on a black background) - http://www.serviator.dk

    :: serviator

  13. #13
    Senior Member
    Join Date
    Jul 2001
    Location
    Planet Earth
    Posts
    298

    How bout a few photoshop secrets

    Well, it is obvious from your designs that you are more than proficient with graphics, i.e. the complex backgrounds on most of the sites on your designs. How bout a couple of tips and tricks for those of us that can program the hell out of flash but can draw a stick figure on paper? At atleast some sites to learn from. I mean I have some skills but am far from a PhotoShop or Illustrator/Freehand expert

  14. #14
    Danny Gomez Creations ® cosmiceye's Avatar
    Join Date
    Mar 2002
    Location
    under a palmtree in Jamaica waiting for psytopia 2005 to begin
    Posts
    982
    I gotta give you props for your site, its awesome.

  15. #15
    Thanks . I hope you'll like the new one too when it comes up in about a month.

    4Sheezy> for checking out cool websites you should go to http://www.cwd.dk, http://www.digitalthread.com, http://www.linkdup.com, http://www.coolhomepages.com and check their links.

    Regarding tutorials on how to do graphics, I don't know if there's any good online, sorry. I have never used them, but always just played around in Photoshop and learned from a multimedia designer school I went to years ago.

    Let me know if I can help any further with info etc.

    :: serviator

  16. #16
    Junior Member
    Join Date
    May 2002
    Posts
    2
    Aghm - what if i wanto make something like _root.movie&num.gotoAndPlay(1); where movieNUm is dynamicly assigned ?

  17. #17
    Senile member! :)
    Join Date
    Dec 2001
    Location
    Saunaswamp (transl)
    Posts
    2,296
    Aghm - what if i wanto make something like _root.movie&num.gotoAndPlay(1); where movieNUm is dynamicly assigned ?
    like this:

    Code:
    _root["moviename" + movienum].gotoAndPlay(1);
    /Mirandir

  18. #18
    Senior Member
    Join Date
    Jul 2001
    Location
    Planet Earth
    Posts
    298

    Thanks Serviator

    I will check those links and also pop you an email if necessary on some techniques in photoshop.

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