Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-02-2005, 02:15 PM   #1
Swashbuckler200
Registered User
 
Join Date: May 2005
Posts: 74
Default Problems implementing two different AS

Hi all

I want to implement two AS scripts at a certain point on my timeline however whilst each individual AS works fine, when I combine the two together one cancels out the other.

The first AS slides each individual menu items when the mouse cursor is over them.

ActionScript Code:
//Global Variables _global.speed = 1.3; _global.stickiness = 8; _global.baseX = 5; _global.finalX = 30; //Movement Functions function moveOut () {     this.xStep = 0;     this.onEnterFrame = function ()     {         if (this._x < finalX)         {             difference = finalX - this._x;             this.xStep = (this.xStep + difference * speed) / stickiness;             this._x += this.xStep;         }         if (this._x > finalX)         {             this._x = finalX;         }     }; } function moveIn () {     this.xStep = 0;     this.onEnterFrame = function ()     {         if (this._x > baseX)         {             difference = finalX - this._x;             this.xStep = (this.xStep + difference * speed) / stickiness;             this._x -= this.xStep;         }         if (this._x < baseX)         {             this._x = baseX;         }     }; } //Assign event handlers vNav001.onRollOver = moveOut; vNav001.onRollOut = moveIn; vNav002.onRollOver = moveOut; vNav002.onRollOut = moveIn; vNav003.onRollOver = moveOut; vNav003.onRollOut = moveIn;

The second AS randomly moves a mc (spiral) around the stage whenever the cursor mouse is over a menu item.

ActionScript Code:
for (i=0; i<4; i++) {     _root["vNav00"+i].onRollOver = function() {         _root.spiral_mc._x = random(Stage.width);         _root.spiral_mc._y = random(Stage.height);         onEnterFrame = function () {             _root.spiral_mc._alpha += 5;         };     };     _root["vNav001"+i].onRollOut = function() {         onEnterFrame = function () {             _root.spiral_mc._alpha -= 5;         };     }; }

Problem is if I combine the two in the order above the menu action script (e.g. the first one) no longer functions.

Any idea how I can solve this problem?
Swashbuckler200 is offline   Reply With Quote
Old 06-02-2005, 03:37 PM   #2
creynders
flash veteran
 
creynders's Avatar
 
Join Date: May 2005
Location: Belgium
Posts: 914
Default

The problem is that you assign a onRollOver event handler to the buttons twice, so the second assignment overwrites the first one.
A possible solution could be to write
ActionScript Code:
vNav001.moveOut = moveOut;
instead of
ActionScript Code:
vNav001.onRollOver = moveOut;

and then in the second piece of code
ActionScript Code:
_root["vNav00"+i].onRollOver = function() {           [U]this.moveOut()[/U]           _root.spiral_mc._x = random(Stage.width);           _root.spiral_mc._y = random(Stage.height);           onEnterFrame = function () {                _root.spiral_mc._alpha += 5;           };      };

and then do the same for moveIn and onRollOut

BTW you should check out variable scoping, it's very important that you understand what the scope of a variable is, look up "var" and the topic "variable scoping" in the flash helpfiles
creynders is offline   Reply With Quote
Old 06-02-2005, 04:27 PM   #3
Swashbuckler200
Registered User
 
Join Date: May 2005
Posts: 74
Default



Many thanks...it worked a treat.

I will look into variable scoping in my text books as it looks as if can save a lot of time.
Swashbuckler200 is offline   Reply With Quote
Old 06-02-2005, 04:32 PM   #4
creynders
flash veteran
 
creynders's Avatar
 
Join Date: May 2005
Location: Belgium
Posts: 914
Default

Quote:
Originally Posted by Swashbuckler200
I will look into variable scoping in my text books as it looks as if can save a lot of time.
Oh, that's not about saving time, it's simply essential
... and agreed it will save you some "pulling out my hair because this *$£µ% thing doesn't do what i want"-time
creynders is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:17 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.