A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: need mouse trail (actionscript 2) with multiple images - troubled newbie...

  1. #1
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121

    need mouse trail (actionscript 2) with multiple images - troubled newbie...

    hi all.

    i humbly approach you again, apologizing for my stupidity... this dummie-newbie is still struggling with the same problem: i desperately need a mouse trail script, where 3 or more different objects chase the mouse in an elastic, smooth and bouncy manner - as if connected to it with a rubber band. i looked through all the mousetrailers in this site and about a dozen(!) others, with poor results: all mouse trailers, where multiple images/graphics follow the cursor are in flash 5 format or older and won't work in my main movie - i use flash mx 2004 7.02.

    i saw that kind of trailer in a web page, and i know it's a really simple thing to do - if you just know how! so please, someone, if you can either point me to a site that has the thing, or paste me those actionscript lines + necessary info bits here, you'd be doing me a really big favor.

    thanks, by the way, for this great site! it has been an important help in my first flash experiments.

    mar

  2. #2
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    i saw that kind of trailer in a web page
    What was the site? It would be easier to understand exactly what effect you are looking for, if it were provided. After a quick search on "elastic", I found a thread here where pellepiano provides a nice elastic scaling effect of an MC. A little tweeking and I came out with this:

    code:

    onClipEvent (load) {
    velocityY = 1;
    differenceY = 1;
    velocity = 1;
    difference = 1;
    }
    onClipEvent (enterFrame) {
    var speed = 5;
    var viscosity = 1.4;
    ymove = _root._ymouse;
    differenceY = ymove-this._y;
    velocityY = (velocityY+(differenceY)/speed)/viscosity;
    this._y += velocityY;
    xmove = _root._xmouse;
    difference = xmove-this._x;
    velocity = (velocity+(difference)/speed)/viscosity;
    this._x += velocity;
    }

    }



    Fool around with the "viscosity" to change it's elasiticity effect.
    Last edited by Quixx; 01-03-2005 at 12:54 AM.

  3. #3
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121

    yes, but i get an error message...

    hi!
    that's just it: i saw that page years ago, and now when i try to navigate back there the bastards have changed their site and gotten rid of the trailer... anyway, it was a simple trailer woth three figures, sort of stickmen trying to grasp the cursor. v ery nicely done...

    i tried your script. i made a mc with 3 figures (fig1,2,3, but when i try to previwe the page it spat me this error message;

    **Error** Scene=Scene 1, layer=trailer, frame=1:Line 20: Unexpected '}' encountered
    }

    Total ActionScript Errors: 1 Reported Errors: 1

    thanks again,
    mar

  4. #4
    user in A minor
    Join Date
    Jan 2005
    Location
    finland
    Posts
    121

    correction to the previous message

    ok,
    i opened my eyes and looked again- and took out the extra {. sorry - i didn't see it first and wondered what was the matter...

    but still, problem: now the figures move as a packet, stiffly together, and not an elastic line! is it in the way i make the movie clip? how should i treat my three graphics?

    thanks thanks thanks,
    mar

  5. #5
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    Sorry about that } bracket. I had adjusted some things and then copied and pasted over what I had there before. I must not have selected all the way down.

    Now to answer your new question... Try changing the instance names of the three figure movies to, "char1", "char2", and "char3". Then make the X and Y positions of "char1" match the mouse position. Then change the X and Y positions of "char2" to match "char1" position, but offset to meet it's width (or point of attachment). The following code is what I put on my test movie for this:

    code:

    onClipEvent (load) {
    velocityY = 1;
    differenceY = 1;
    velocity = 1;
    difference = 1;
    }
    onClipEvent (enterFrame) {
    var speed = 4;
    var viscosity = 1.6;
    ymove = _root.char1._y;
    differenceY = ymove-this._y;
    velocityY = (velocityY+(differenceY)/speed)/viscosity;
    this._y += velocityY;
    xmove = _root.char1._x+25;
    difference = xmove-this._x;
    velocity = (velocity+(difference)/speed)/viscosity;
    this._x += velocity;
    }



    Notice that the ymove variable is set to follow "char1" Y position and that it's xmove is set to follow "char1" X position + 25. The 25 is added as an offset, so that "char2" will match up where I want it to next to "char1". You will have to change that number to meet your needs.

    When you put the code on "char3", change any lines that use "char1" to "char2", so that it will follow the right MC.

    I've attached a fla file for this.

  6. #6
    Junior Member
    Join Date
    Jan 2005
    Posts
    8

    yup, but but ...

    thanks for the attachement! nice: it cleared a lot of things - so far, i'm still struggling, i guess. newbies have to learn it all...

    quick question: i got only one of my characters, the one with an instance name char 1, moving and following the cursor. the other two stay stuck. i noticed that you're using only one symbol in your sample movie. in my mc i have three symbols (all very different in shape, colour etc, i drew them separately): they're different instancens. is that where the problem lies?

    again - thanks,
    mar

  7. #7
    Junior Member
    Join Date
    Jan 2005
    Posts
    8

    it's me despite the nick

    ...forgot to mention: the system sometimes accepts my real nick, sometimes not. damned if i know why - so i at times i have to use a spare nick...
    mar

  8. #8
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    You should be able to put the code on each individual MC and still have it work with no problem. Maybe you forgot to change the instance names. Is it possible for you to attach the fla file you are currently working on, so I can take a look?

  9. #9
    Junior Member
    Join Date
    Jan 2005
    Posts
    8

    test site

    hi again!

    ok, here's the fla... a friend of mine makes hand-woven gnomes for a living, believe it or not! ...hence the 'hand-made' look... it still lacks preloaders (i'll try those soon) and background design etc etc, you'll see. so i made three separate mc's follow the cursor, just toggling their speed and viscosity values to make them look something like a line, although it's not, really.

    another thing: as i'm aware that many don't like trailers or get bored with them really quick, i wanted to insert a button to stop, maybe also to start the trailer. how to do that with this code..? i have the buttons there already, without actions.

    thanks *bows*
    mar
    Last edited by mrk 13 again; 01-03-2005 at 03:13 PM.

  10. #10
    Junior Member
    Join Date
    Jan 2005
    Posts
    8

    here's the file...

    had to remove other stuff, it was too big.
    mar
    Attached Files Attached Files

  11. #11
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877

    Yikes...

    Coincidently, I had already started to try and make a code that attachs the gnomes (in my case links) dynamically. The way I was handling things before, it would be difficult to add and remove the gnomes, because they would loose there script after being removed from the movie.

    While I'm not sure if it's the best way to handle it, I came up with this code (which can be found on the "buttons" layer):

    code:

    gnomeOnOff = false;
    function addGnomes() {
    for (i=1; i<4; i++) {
    _root.attachMovie("gnome"+i, "gnome"+i, i, {velocityY:1, differenceY:1, velocity:1, difference:1});
    _root["gnome"+i].speed = 4;
    _root["gnome"+i].viscosity = (((1+(i+2))/10)+1);
    // trace(_root["gnome"+i].viscosity);
    _root["gnome"+i].ng = i-1;
    if (i<2) {
    _root["gnome"+i].onEnterFrame = function() {
    this.ymove = _root._ymouse;
    this.differenceY = this.ymove-this._y;
    this.velocityY = (this.velocityY+(this.differenceY)/this.speed)/this.viscosity;
    this._y += this.velocityY;
    this.xmove = _root._xmouse+50;
    this.difference = this.xmove-this._x;
    this.velocity = (this.velocity+(this.difference)/this.speed)/this.viscosity;
    this._x += this.velocity;
    };
    } else {
    _root["gnome"+i].onEnterFrame = function() {
    this.ymove = _root[("gnome"+this.ng)]._y;
    this.differenceY = this.ymove-this._y;
    this.velocityY = (this.velocityY+(this.differenceY)/this.speed)/this.viscosity;
    this._y += this.velocityY;
    this.xmove = _root[("gnome"+this.ng)]._x+50;
    this.difference = this.xmove-this._x;
    this.velocity = (this.velocity+(this.difference)/this.speed)/this.viscosity;
    this._x += this.velocity;
    };
    }
    }
    }
    gnome_btn.onRelease = function() {
    if (gnomeOnOff) {
    addGnomes();
    gnomeOnOff = false;
    } else {
    for (i=1; i<4; i++) {
    removeMovieClip("gnome"+i);
    }
    gnomeOnOff = true;
    }
    };
    addGnomes();



    With this code, you won't need any other code placed directly on each "gnome" MC and, in fact, you won't have the gnome MC's on the stage at all to begin with. The gnomes are attached dynamically with actionscript and then given their code upon being attached to the main movie. If you click on the button ("gnome_btn") they will be removed from the movies stage. Clicking the button again, will reattach the gnomes.

    You only need to make sure you have the gnomes "Linkage Properties" set to "gnome1", "gnome2" and "gnome3" (not just their library names). Then give your buttons "Instance Name" the name "gnome_btn".

  12. #12
    Junior Member
    Join Date
    Jan 2005
    Posts
    8

    wow!

    mmmmann... aren't these actionscripts evil!

    yesss: i got it working. TA-ta-ta-TAAAA!! it's a really neat piece of script! i'll go through it bit by bit, see how much sense i can make out of it... my big sister's kid, 3 yrs, had a lot of fun with the gnomes for a long time, so i guess it just has to be all right.

    thank you veeeeeeryveryvery much
    *bows in deep gratitude*
    mar
    Last edited by mrk 13 again; 01-03-2005 at 06:58 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