dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: controlling an animation based on external inputs

  1. #1
    Member
    Join Date
    Feb 2003
    Posts
    30

    controlling an animation based on external inputs

    Hello all,

    I'm fairly new to flash but i have some fairly ambitious ideas I would like some help in. These are my main questions (for now)...

    1) I would like to display a thermometer that changes temperature according to the value in a text file... how does that work?

    2) I would like to change the rotational speed of a fan based on a value from a text file... and how do i get the fan to rotate in the first place!!

    3) Can i make the above alterations real-time?? i.e. for the thermometer/fan to change as soon as the text file is changed+saved?
    If so, please shed soe light...

    I am using Flash MX...

    Thank you in advance and awaiting a reply!

    Haider

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    In textfile...

    temp=76&speed=2

    Save as text.txt

    Load the text into flash (on first frame of main timeline ).
    loadVariablesNum("text.txt",0);

    //Temp
    1. Make a movieclip with 100 frames. make a tweening of the temperature going from 0 till 100.
    In the first frame of the movieclip......
    gotoAndStop(_root.temp);

    // Fan
    2. Make the fan as a movieclip (just one frame). Put this on the movieclip.

    onClipEvent (enterFrame) {
    this._rotation += int(_root.speed);
    }

    To maually change the fan speed make a input textfield in the main timeline called speed and change the value there.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    Member
    Join Date
    Feb 2003
    Posts
    30
    Thanx for the reply pellepiano,

    The fan one worked beautifully...

    However, the temp goes through the whole tween then stops at the value in text.txt... is there any chance of preventing it from going through the whole animation, and just let it stop at the value in the text file??

    Thanx once again...

    Haider

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    That is not supposed to happen. Try to have the temp movieclip on the second frame instead in your main timeline or have a stop action in the first frame of temp and target it from the main timeline with.........

    tempMC.gotoAndStop(temp);

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  5. #5
    Member
    Join Date
    Feb 2003
    Posts
    30
    i didn't quite get how to do the last bit...

    i basically have 1 frame in my main timeline, and that has a movieclip in it. This movie clip contains the thermometer and the tween with 100 frames.

    So:
    loadVariablesNum("text.txt",0);

    is on the main timeline, and the first frame of the tween (within the movieclip) is:

    gotoAndStop(_root.temp);

    temp is the variable i'm usin, and my movieclip is called temp_test... to be honest i don't know what tempMC is...

    Please shed some light and i apologise for the hassle, but your help is much appreciated!!

    Haider

  6. #6
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    As i didnt know the name of the mc I called it tempMC so you would know which mc I meant.
    Your Flash movie has to read the textfile first and then distribute the variables that should be executed.
    I suggest you move your temp_test mc 10 frames in the timeline so the variables has a chance to load first. On the tenth frame you could have......

    temp_test.gotoAndStop(temp);

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  7. #7
    Member
    Join Date
    Feb 2003
    Posts
    30
    load time was definitely the problem... since i moved the movie clip 10 frames down the mc timeline i have managed to avoid the animation running all the way (thanks!)

    Now the thermometer displays the value read from the text file, but is it possible to use the tween to allow the thermometer to be more animated?? i.e. it now displays the value, not the temp going towards the value...

    Is there a function not quite "gotoAndStop" but more like "uptoAndStop"... maybe a function that can determine how many frames to play???

    Thanks once again!!

    Haider

  8. #8
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Then use a new action instead, ON the movieclip.

    if(this._currentframe == Number(_root.temp){
    stop();
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  9. #9
    Member
    Join Date
    Feb 2003
    Posts
    30
    i figured out how to do the animation recently!! Thanks a lot pellepiano!!

    But i have a [couple of] follow-up question(s) (if you don't mind!):

    Say, for example, the temperature goes from 0 to 30, but then i change the variable in the text file to 40:

    1) can i make the animation go from 30 to 40, instead of starting at 0?

    2) how about going to a lower number? (e.g. from 40 to 30)

    I really appreciate your help...

    Haider

  10. #10
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    This should cover for back and forward animation.I think

    if(this._currentframe == Number(_root.temp){
    stop();
    }
    if(this._currentframe > Number(_root.temp){
    prevFrame();
    }
    if(this._currentframe < Number(_root.temp){
    nextFrame();
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  11. #11
    Member
    Join Date
    Feb 2003
    Posts
    30
    thanks pellepiano...

    but how can i get the flash to realise that the text file has been changed in order to respond to the change? something on the verge of real-time

    Haider

  12. #12
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Flash can not know that by itself. Or you can load the textfile in intervals.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

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