View Full Version : Why doesn't this code work on Flash Player 9?
dududis
March 28th, 2008, 02:11 PM
Hello!
I don't really understand the differences between Flash player's versions, so I don't know why this code doesn't work properly. Can anyone point me what's wrong?
_root.centrey = 272;
_root.centrex = 510;
_root.onEnterFrame = function() {
valeur_a = (_root._ymouse-_root.centrey)*0.5;
valeur_b = valeur_b+valeur_a;
valeur_b = valeur_b*0.8;
_root.animation.block1._y = (valeur_b-_root.animation.block1._y)*0.05;
_root.animation.block2._y = (valeur_b-_root.animation.block2._y)*0.1;
_root.animation.block3._y = (valeur_b-_root.animation.block3._y)*0.15;
_root.animation.block1._x = (_root._xmouse-_root.centrex)*0.02;
_root.animation.block2._x = (_root._xmouse-_root.centrex)*0.04;
_root.animation.block3._x = (_root._xmouse-_root.centrex)*0.06;
};
Thanks!
Ordinathorreur
March 28th, 2008, 02:46 PM
ActionScript 3 has changed a bit. Here are some changes you will need to investigate before trying to fix your script.
_root is no longer used, been replaced by "stage"
properties no longer have an underscore before them (for instance _ymouse is now mouseY)
The event system has changed completely, look up addEventListener() and removeEventListener()
That said, you can still publish a Flashplayer 8 file from CS3 which will run just fine in the newwest Flashplayer too. All you need to do is change your publish settings and your fla should complie just fine with the code you posted.
icio
March 28th, 2008, 02:49 PM
How exactly is it "not working"? Perhaps you are publishing to ActionScript 3 by mistake.
dududis
March 28th, 2008, 03:06 PM
Ordinathorreur, thanks for you reply. I'm using CS3, but working with actionscript 2.0, forgot to tell that on my post.
Icio, I'm publishing using actionscript 2.0, for flash player 9. No mistake on that.
Just one part of the code works, the _x axis.
icio
March 28th, 2008, 03:12 PM
I don't think this will solve the problem, but you would be declaring your variable properly.
var valeur_a:Number = ...
Can we see it in action or have source?
dududis
March 28th, 2008, 03:22 PM
I don't think this will solve the problem, but you would be declaring your variable properly.
ActionScript Code:
var valeur_a:Number = ...
Can we see it in action or have source?
Source attached. If you open the file and export it for player 9, actionscrip 2.0, the y axis doesn't work.
icio
March 28th, 2008, 03:58 PM
This should do the trick - it was difficult to find the problem without going through the steps.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Merci pour votre intérêt en dunun.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Avant tout je bloque le "resizage" de mon animation pour conserver ses dimensions à 100%
Stage.scaleMode = "noScale";
// Je définis les centres x et y de mon animation.
_root.centrey = 250;
_root.centrex = 275;
/**
* We need an initial value for this because we use it in the calculation of itself.
* Unlike with ActionScript 1.0, where undefined variables used in mathematical expression take default value 0,
* using undefined variables in mathematical expressions in ActionScript 2.0 will return NaN.
*/
_root.valeur_b = 0;
_root.onEnterFrame = function() {
// Cette formule donnera de l'inertie à l'axe des y.
valeur_a = (this._ymouse - this.centrey) * 0.5;
_root.valeur_b = (_root.valeur_b + valeur_a) * 0.8;
// Je rend l'aspect de distance à mon animation en affectant un facteur croissant à mes différents blocks
_root.animation.block1._y = (_root.valeur_b - _root.animation.block1._y) * 0.05;
_root.animation.block2._y = (_root.valeur_b - _root.animation.block2._y) * 0.1;
_root.animation.block3._y = (_root.valeur_b - _root.animation.block3._y) * 0.15;
_root.animation.block4._y = (_root.valeur_b - _root.animation.block4._y) * 0.2;
_root.animation.block5._y = (_root.valeur_b - _root.animation.block5._y) * 0.25;
// L'axe des x suivra simplement la souris.
_root.animation.block1._x = (_root._xmouse - _root.centrex) * 0.02;
_root.animation.block2._x = (_root._xmouse - _root.centrex) * 0.04;
_root.animation.block3._x = (_root._xmouse - _root.centrex) * 0.06;
_root.animation.block4._x = (_root._xmouse - _root.centrex) * 0.08;
_root.animation.block5._x = (_root._xmouse - _root.centrex) * 0.1;
};
//voilà, c'est tout simple.
Hope that helps :thumb:
dududis
March 28th, 2008, 04:30 PM
Thank you very much icio! I would never be able to figure that out! :}
icio
March 29th, 2008, 04:53 PM
Glad I could help :thumb:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.