dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: where to put continuously executing script

  1. #1
    Member
    Join Date
    Dec 2000
    Posts
    40

    where to put continuously executing script

    hello,

    i'm new to flash but not to programming...
    i'm trying to create a button-like effect whereby an image becomes brighter and brighter (alpha goes from 0-->100) the longer the mouse stays over it. and conversely, the button fades away slowly once the user moves his mouse away from it.

    i'm coming from a background of programming in lingo, where i would have just put an if then type of statement in the first frame, which would then be executed all the time.

    i have noticed that in flash, my script in the first movie frame (below) is getting executed once only.

    mc_hit01.onRollOver = function () {
    mc_hit01._alpha = Math.min (100, mc_hit01._alpha + 5);
    }

    it is not executing WHILE i am over the button, but only once each time i pass over it.

    is there a way to make a flash movie 'loop' the way it would in director ? if not, how/where do i put code that should continuously execute ? in the movie clip itself ? (would prefer to keep all my scripts in one place, the first frame, if possible, but if that's the only way to do it...)

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    code:
    mc_hit01._alpha = 0;
    mc_hit01.onEnterFrame = function() {

    t = mc_hit01.hitTest(_xmouse, _root._ymouse);
    t ? (this._alpha<=100 ? this._alpha++ : this._alpha=100) : (this._alpha>0 ? this._alpha-- : this._alpha=0)
    }


    or
    code:

    mc_hit01.onRollOver = function(){
    t = true;
    }
    mc_hit01.onRollOut = function(){
    t = false;
    }
    mc_hit01.onEnterFrame = function(){
    t ? (this._alpha<=100 ? this._alpha++ : this._alpha=100) : (this._alpha>0 ? this._alpha-- : this._alpha=0);
    }


  3. #3
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    Maybe something like this....

    code:

    _root.clip._alpha = 0;
    myFader = function (myTarget, alpha) {
    this.onEnterFrame = function() {
    if (alpha == true && myTarget._alpha>=0) {
    myTarget._alpha -= 10;
    } else if (alpha == false && myTarget._alpha<=100) {
    myTarget._alpha += 10;
    }
    }
    }
    myButton.onRollOver = function() {
    _root.myFader(clip, 0);
    }
    myButton.onRollOut = function() {
    _root.myFader(clip, 1);
    }



    Edit*** Oops, didn't see sergwiz reply before I posted. One thing to mention in sergwiz code that often confuses folks, did me for a long while, is the use of a nested conditional......
    code:

    t ? (this._alpha<=100 ? this._alpha++ : this._alpha=100) : (this._alpha>0 ? this._alpha-- : this._alpha=0);


    This is just shorthand for an if statement.
    Last edited by NTD; 12-12-2004 at 12:47 PM.

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