A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: A function that can change variables within MCs.

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    2

    A function that can change variables within MCs.

    Hi. I'm not new to Flash, but I'm a bit rusty. I'm working on a game in ActionScript 2.

    I am writing a function that I will use to tell characters in the game how they appear. Each character MC has a bunch of variables used to determine its appearance. Things like what they are wearing, what their facial expression is, what they are holding, etc.

    The function is called wearThis() and I'm making it so that it is triggered from within the character MCs upon loading, but can also be triggered from anywhere else, should the character's appearance need to be changed during the events of the game. The function is on the root timeline.

    I'm having trouble actually figuring out how to have a function work though. The issue is I can't get it to change those variables. I'll simplify it here, this is how I believed I could change those variables within the mc:
    Code:
    function wearThis(mc) {
    	_root[mc].hairColor = 12; 
    	_root[mc].hatColor = 5; 
    	_root[mc].hatType = 6; 
    }
    and it would be called from within the MC by the line
    Code:
    _root.wearThis(this)
    I would expect this would set hairColor etc to their appropriate values, but it doesn't.

    If I run a trace(mc) in the function, I get "_level0.steve" or whatever the MC's name is, which is what I expected.

    Figuring I was doing something wrong, I swapped my variables for _alpha.

    Code:
    function wearThis(mc) {
    	_root[mc]._alpha = 50; 
    }
    Which turned every single object in the fla file 50% alpha, including shapes that weren't even in movie clips. Which makes it clear that I'm not pointing things at the right spot.

    Please help me out here.

  2. #2
    Junior Member
    Join Date
    May 2014
    Posts
    2
    No help here?

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