all groups > flash actionscript > april 2005 >
You're in the

flash actionscript

group:

changing variables mucks up 3D motion


changing variables mucks up 3D motion scottPadgett
4/26/2005 12:00:00 AM
flash actionscript:
Hi folks,

I've got this 3D model of something like electrons orbiting a center point and
it worked fine as a stand-alone movie where the parameters of the motion were
set in variables in frame one upon loading.

Then I added input text fields with the motion variables assigned to them so
that you could change radius of orbit on the fly, etc. Problem is when you
vary some of these fields by typing in new values, the results are screwy.
If you vary the size of the objects rotating to say 50 for example, you'll see
the change is applied on the fly and the size of the objects simply increases
as they orbit. But if you vary any other settings you get no results at all or
very screwy results.

For example try entering '0.5' into the DTheta field verses changing it in the
Actionscript for frame 1 before testing the movie... Hard coding it just
increases the electrons rotation speed, as it should, but changing the variable
field in the published movie causes slow and erratic behavior and proper orbit
is no longer achieved.

I think that for some reason you just can't change certain variables on the
fly without restarting the movie, but I tried a version where the orbiting
objects were in a movie loaded into a subclip, referenced variables in the root
container clip and had a button to reload that subclip after changing the
variables and it still behaves almost identically.

Any help would be greatly appreciated. Thanks.

http://adams-solutions.com/flashDev/orbitMotion_varFields.fla
Re: changing variables mucks up 3D motion David Stiller
4/26/2005 12:00:00 AM
Scott,

[quoted text, click to view]

Your functions are expecting numbers, but I suspect they're getting
strings. Have you made sure to convert your text field .text property
values into numbers?

myNumber = Number(myTextField.text);


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: changing variables mucks up 3D motion scottPadgett
4/26/2005 12:00:00 AM
Hi David,

I thought it might be something like that, but the size value was working correctly?? If the variable type was off, that field shouldn't work either right?

Re: changing variables mucks up 3D motion scottPadgett
4/26/2005 12:00:00 AM
David,

I tried the following to try to type the text properties to numbers but it
didn't change anything. Am I on the right track here?

AS___________________


// GLOBAL VARIABLES DESCRIBING ORBIT BEHAVIOR


// delta Theta to control speed of orbit in combination with Frame Rate
//var DTheta = 0.02181661565;
DTheta = Number(DTheta_txt.text) = .1;

// thetaCoeffecient is increment that each electron is offset from the others
in radians.
thetaCoefficient = 1.2;

// orbitOffset is the radians each plane of orbit is rotated about the y axis
when rendered by the engine

this.createEmptyMovieClip("counter_mc",200000);
this.counter_mc.onEnterFrame = function ()
{

if (!this.counter)
{
this.counter = .05;
}
_root.orbitOffset = (30 + this.counter) * (Math.PI / 180);

this.counter = this.counter + .05;

//trace("counter = "+ this.counter);
}




// set the smallest radius orbit for a ball
baseRadius = Number(baseRadius_txt.text) = 100;

// vary orbit increment. this is the difference between the innermost and
all the other orbit radi
outerRadius = Number(outerRadius_txt.text) = 100;



// fixed based on Document settings z is always zero at screen and positive
'into' it.
orbitCenterX = 300;
orbitCenterY = 200;
orbitCenterZ = Number(orbitCenterZ_txt.text) = 300;


// vary at will to change scale of orbiting object
size = Number(size_txt.text) = 20;

// here we define the distance of observer from the screen

f = Number(f_txt.text) = 400;


// visibility is defined here higher the less falloff in alpha at distance
visibility = Number(visibility_txt.text) = 30;

_____________________


Otherwise I left the movie alone, short of naming the textboxes instances to
the appropriate names.

You can see the modified file at the same address as previously:

http://adams-solutions.com/flashDev/orbitMotion_varFields.fla
Re: changing variables mucks up 3D motion scottPadgett
4/26/2005 12:00:00 AM
OK my assignment idea there is all wrong. Not sure how to assign these
properties correctly within my application...

Going to lunch. To hungry to think.

BTW is this forum application really buggy or what? I just tried to post and
it was lost somewhere along the way... Happens all the time to me, and tons of
ColdFusion errors during routine use.
Re: changing variables mucks up 3D motion scottPadgett
4/26/2005 12:00:00 AM
David,

I did as you prescribed and set the variables equal to the text values run
through the Number method. I simply entered manually some initial values for
the fields on the Flash stage, so that there would be initial values.

So now this is even weirder, because the movie is running correctly upon first
loading, and it's pulling variable values FROM the text fields directly. So
there's seemingly nothing wrong with the variable values getting to the
Actionscript intact. But as soon as I change any value but the 'size'
variable, things get screwy.

I'm really confused here. But I think maybe something about how the variables
are acted upon or used in my code makes it so that when they're changed while
the app is actually running, some values get mucked up before the app repeats
one cycle with the new value. The size variable is only used in one statement
and it runs at the tale end of the per-frame actions...

Gotta be something like this, no?

Updated version at:

http://adams-solutions.com/flashDev/orbitMotion_varFields.fla
Re: changing variables mucks up 3D motion David Stiller
4/26/2005 12:00:00 AM
Scott,

[quoted text, click to view]

I *think* I found the problem, but you'll have to tinker with it.
You're pulling from the text fields' .text properties in your ActionScript,
but in addition, you have the Var: field filled in for each instance via the
Properties panel. Clear out those Var: fields! That's the way it used to
work in Flash, and you're pulling from the text fields' .text properties
instead.

That Var: backdoor may be confusing things because it's a direct line to
the text fields' .text properties, only the Var: version isn't getting
converted to a number.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."


Re: changing variables mucks up 3D motion David Stiller
4/26/2005 2:21:31 PM
[quoted text, click to view]

Yeah, I was a bit confused. I'll get back to that in a minute.

[quoted text, click to view]

I recommend using the NNTP feed instead. The web interface *is*
frustrating. Fire up Outlook Express or Thunderbird and head to
forums.macromedia.com instead.

As for your assignments:

[quoted text, click to view]

The reason this won't work (I believe) is because assignments work from
right to left. 100 will be assigned to the .text property of
outerRadius_txt, which in turn will be assigned to outerRadius. In this
context, I'm not sure how the Number() function works ... I think it just
doesn't make sense here. But in any case, outerRadius will always equal a
hundred here.

If you simply want outerRadius to equal the value of outerRadius_txt, do
this:

outerRadius = Number(outerRadius_txt.text);

If you want outerRadius to equal the value of outerRadius_txt *only if
it has a value,* and 100 if it doesn't, do this:

// either this, using the ternary operator
outerRadius = (outerRadius_txt.text != "") ? Number(outerRadius_txt.text) :
100;

// or this, which is equivalent
if (outerRadius_txt.text != "") {
outerRadius = Number(outerRadius_txt.text);
} else {
outerRadius = 100;
}

Note that neither of these tests whether the value of outerRadius_txt's
text property is a valid number. Users *might* enter a string, like "asdf".
What then?

You might experiment with the parseInt() or parseFloat() functions.

if (outerRadius_txt.text != "") {
if (parseFloat(outerRadius_txt.text) > 0) {
outerRadius = Number(outerRadius_txt.text);
// or outerRadius = parseFloat(outerRadius_txt.text);
}
} else {
outerRadius = 100;
}

... or maybe ...

if (outerRadius_txt.text != "") {
if (!isNaN(parseFloat(outerRadius_txt.text))) {
outerRadius = Number(outerRadius_txt.text);
}
} else {
outerRadius = 100;
}


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: changing variables mucks up 3D motion Scott Padgett
4/26/2005 3:37:50 PM
OK, that sounds like it might be the ticket. I'm going to try it out.

PS got the newsfeed coming into Outlook. Much better.

[quoted text, click to view]
Re: changing variables mucks up 3D motion Scott Padgett
4/26/2005 3:57:19 PM
David,

You were right. I got rid of the 'variable' fields in the property
inspector and am relying on the textField.text property alone.

I had to add a button into the mix to reload the variables once the input
fields are altered, but I already had that version brewing anyway...

So I now have the input fields and a 'reload' button in the main movie. The
button loads a movie into a clip that contains a single object and the
Actionscript to dupe it and move the dupes around. That button also calls a
function that sets all the variables according to the input fields, before
loading the sub clip. All works great!

Thanks for your help. I really appreciate you taking a few looks at this.



[quoted text, click to view]
Re: changing variables mucks up 3D motion David Stiller
4/26/2005 4:01:04 PM
[quoted text, click to view]

Glad to hear it, Scott.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

AddThis Social Bookmark Button