Tween Class Or Custom Built Math Functions?
Just wondering on opinions of using the tween class for movement over building your own movement function. I've never used the tween class and I feel it is a bit limiting as I can't seem to figure out how to control how much bounce, etc. and it seems like a factory generated amount.
Do most people use the tween class or build their own. This is the kind of function I would build normally:
ActionScript Code: var mybox:box = new box();addChild(mybox);mybox.x = 0;var xspeed:Number = 0;//mybox.addEventListener(Event.ENTER_FRAME, mover);function mover(event:Event):void { var xpos = 500 var speed = 5 var bounce = .6 // xspeed += (xpos-mybox.x)/speed; xspeed *= bounce; mybox.x += xspeed; if (mybox.x<xpos+.2 && mybox.x>xpos-.2 && xspeed<.1) { mybox.removeEventListener(Event.ENTER_FRAME, mover); }}
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 02-22-2008, 02:33 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Using Built-in Tween Class - Need Action Upon Finish
I am new to this so thanks for your patience. I currently have set the "portfolio" button so that when you click on it, it transitions whatever is currently on the screen out (for example, the home page is loaded all the home contents will tween out).
The code I've got for this is:
Code:
//paper transition out
_root.xpaper = _root.small_paper._x;
_root.ypaper = _root.small_paper._y;
_root.xscalepaper = _root.small_paper._xscale;
_root.yscalepaper = _root.small_paper._yscale;
new mx.transitions.Tween(small_paper, "_y", mx.transitions.easing.Strong.easeInOut, _root.ypaper, -10000, 1.75, true);
new mx.transitions.Tween(small_paper, "_x", mx.transitions.easing.Strong.easeInOut, _root.xpaper, -10000, 1.75, true);
new mx.transitions.Tween(small_paper, "_yscale", mx.transitions.easing.Strong.easeInOut, _root.yscalepaper, 450, 2, true);
new mx.transitions.Tween(small_paper, "_xscale", mx.transitions.easing.Strong.easeInOut, _root.xscalepaper, 450, 2, true);
Now once this is done I want to load the portfolio page, which I know I do using:
Code:
gotoAndPlay("portfolio");
The problem is if I put the gotoAndPlay in the onRelease section of the button the above tweens don't happen because it just switches to portfolio. How can I set it up so the gotoAndPlay doesn't happen until my tweens are finished?
Thanks
Custom Math Functions
I going through the book ActionScript Cookbook by O'Reilly, and I can't seem to add a custom math method. Here is a simple example:
Math.timesTwo = function(num){
return num*2;
}
trace(Math.timesTwo(5));
I get the following error:
**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 4: There is no property with the name 'timesTwo'.
Math.timesTwo = function(num){
Can someone tell me what I am doing wrong ?
Thanks
John
Custom Math Class
I want to make a custom class similar to "Math", which you don't need to create an instance of to use. So how do you disable instantiation?
Another thought.. If i have a big class called myMath for example with a lot of public functions in it for a lot of different things, if i import that class-file then all the other functions in it will be imported as well right? even if i dont use them?
In that case wouldn't it be better with a class file for each function? How would i go on about doing that?
For example a function called findClosestPoint.
then to use it I would first have to refer to findClosestPoint and then a function in it, right?
so I'd have to do something like findCloestPoint.calculate(), which looks pretty ugly doesn't it? is there some better way?
Any advices are welcome. Thanks..
? Is It Possible To Combine Tween Class And Math ?
Hi,
I am wondering if it is possible to add tween easing to the end of a math rotation formula? In my example I am using the mouse location to control the rotation of an object on the stage (using MOUSE_DOWN and MOUSE_MOVE events). I click and hold the mouse button to start the rotation of the object. When I release the mouse button, the listener for the MOUSE_MOVE is removed and rotation is stopped.
I am rotating the earth on the y-axis using the x-position of the mouse (3D scene):
earth.rotationY = rotationYStart + (mouseXStart-mouseX)/2;
I would like to add some easing to the end of the rotation (not just stop on a dime). I didn't know if it is possible to add a tween to the end to achieve the easing or if I would need to write some new formula to do the same thing (and not use the Tween class). If I need to write another formula, any suggestions on what that might be (quadratic ease out for instance)?
Thanks for any suggestions!!
-Brian
Tween Class Applied In Custom Class Not Working
var sizerW:Object = new Tween(pda_mc,"_xscale",mx.transitions.Tween.None.e aseNone,pdaOrigW,pdaSmallW,3,true);
this code produces and error when applied in a custom class but not in a fla?
the error = There is no property with the name 'None'.
Tween Class In Custom Extend MovieClip Class
I want to use the tween prototype in a custom class that extends MovieClip. I am already including "lmc_tween.as" in my root and I have already replaced the "MovieClip.as" file in my flash directory with the one from the shared/Zigo directory. However, I still get compiler errors if I try to include "lmc_tween.as" in the class file, or without the include in the class it will compile but the tween prototype will not work in the custom class. Does anyone know how to fix this?
How Do I Make My Custom Math Class Methods Persist Across Levels?
Well, just what the title says.
On _level0 I've added a couple of tween calcuations to the Math object. Let's call it Math.calcTween(). I would have expected this to become available through the Math object in my other SWF that I load in _level1, but that doesn't seem to be the case. Have do I make the Math object update persist across all files and levels? Does the _global keyword have anything to do with it?
Cheers,
Terpentine
Tween Class Vs Custom Tween?
I have searched for info on the Tween class, gave up when I found little to nothing on it, so here I am with some questions.
1 - Can I use this class in MX 2004 or is it in 8 only? If so, what is the invocation script?
2 - How flexible is the easing of the Tween class? Can it do more than just fast/slow in/out (fully customizable time curves)?
3 - Can you specify a finite amount of time in which the current invocation of Tween must be completed, or do you have to calculate and apply values to enforce this?
Thanks,
+Q__
Tween In Custom Class
I'm a relative flash/actionscript newbie. I created a towers of hanoi solution moving movie clips around using Tweens. This all worked great when the action script containing the Tween creation existed on what I guess is the root movie clip (within the Action script window of my .fla file).
I tried moving the hanoi solution into a custom class (extending EventDispatcher) and now the tween does not 'run'. I've stepped through my code with the debugger and added plenty of trace statements and am pretty sure all the arguments to the Tween constructor are correct.
_currentTween = new Tween(_movingDiskMc, "_y", Regular.easeOut, _movingDiskMc._y, _yMin, _duration);
Is there something fundamental I'm missing? Is the frame rate an issue with the custom class? The value of _duration above is 5.
thx
- Kurt
Creating Functions With The Tween Class
I'm working with the Tween class in Flash 8. It's great stuff, except I find my ActionScript is getting excessively lengthy. For example, I have ten instances of buttons on stage. They all utilize this particular bit of code, which makes the buttons pop upward:
ActionScript Code:
button1.onRollOver=function(){
//initailizing the Tween
var popBtn:Tween=new Tween(button1, "_y", mx.transitions.easing.Elastic.easeOut, 0, -20, 2, true);
//calling the tween object
popBtn.start();
}
The only difference for any of the buttons in the script is the name of the instance. When i set this up as a global function, using "this" instead of a specific instance name, the script fails to execute. So I have to hammer out all those lines of code for each button instance.
Thanks in advance for any help!
Mx 2004 Tween Class Functions
I use this function often. It is nothing new, and no im not a purist. Im hoping that having this information here, may help someone else in some way.
easing methods;
Strong
Back
Elastic
Regular
Bounce
None
easing types;
easeIn
easeOut
easeInOut
easeNone
make something tween
ActionScript Code:
overTween = mx.transitions.easing.Strong.easeOut;//(instance, property, tweentype, start val, end val , time )tweenIt(myInstance.hl, "_alpha", overTween, 0, 100, 2);
the function that makes stuff tween
ActionScript Code:
function tweenIt(Ttarget, Tprop, TeaseType, Tbegin, Tend, Ttimet) { target=Ttarget, prop=Tprop, easeType=TeaseType, begin=Tbegin, end=Tend, timet=Ttimet; myTween = new mx.transitions.Tween(target, prop, easeType, begin, end, timet, true);}
let me know of anyway I could improve this
Creating Functions With The Tween Class
I'm working with the Tween class in Flash 8. It's great stuff, except I find my ActionScript is getting excessively lengthy. For example, I have ten instances of buttons on stage. They all utilize this particular bit of code, which makes the buttons pop upward:
ActionScript Code:
button1.onRollOver=function(){
//initailizing the Tween
var popBtn:Tween=new Tween(button1, "_y", mx.transitions.easing.Elastic.easeOut, 0, -20, 2, true);
//calling the tween object
popBtn.start();
}
The only difference for any of the buttons in the script is the name of the instance. When i set this up as a global function, using "this" instead of a specific instance name, the script fails to execute. So I have to hammer out all those lines of code for each button instance.
Thanks in advance for any help!
Tween Class, Functions And Loop
Hey! Could use some help here...
I have a bunch of mc's, called like mc1, mc2, mc3 and so on.
What I'd like to do is to tween those in order, with the tween class. So when mc1 is finished, I want mc2 to start and so on.
This is of course possible when writing something like
Code:
var testTween:Tween = new Tween(...);
testTween.onMotionFinished = function():void{
var testTween:Tween = new Tween(..);
}
But when you got like 36 pieces or something, this tween gets really big. Is it possible to use some kind of loop to get the same result? Or maybe a function that gets one movieclip at a time?
Thanks in advance
Problem Calling Functions Inside Custom AS 2.0 Class
Hey yall!
Ok here´s my gamepage, what I want to do is let a lister triggered function create a new timer, but somehow it doesn´t work. Hope anyone hava a clue, I´m so tired of these problems.
Code:
class classesUI.GamePage extends MovieClip
{
private var timeKeeper:TimerExtended;//Special class
private var roundTimes:Number;
private var roundTimeKeeper:Number;
private var gameTimeKeeper:Number;
public function GamePage()
{
}
//Init
function onLoad()
{
roundTimes = 0;
roundTimeKeeper = timeKeeper.intervalCall(1000, -1, Delegate.create(this, roundTimer));
//This works, but I don´t want to do this here, I want to do this on onGameStartEvent();
addTimer();
}
private function roundTimer():Void
{
//This works
roundTimes = roundTimes + 1;
_root.mainShell.roundTimer_txt.text = "Round timer:" + roundTimes;
}
public function addTimer():Void
{
gameTimeKeeper = timeKeeper.intervalCall(1000, 60, Delegate.create(this, timerTick));
}
public function timerTick():Void
{
//this never gets triggered unless from onLoad(), why is that??
_root.oppTimer--;
}
//This function is beeing called from another class with this class registered as a listener
public function onGameStartEvent(newGameStartEvent:GameStartEvent)
{
addTimer();
}
}
Drawbacks To Custom Tween Class?
Hello-
I have a general concern. I am a web designer for an ad agency and I am the main flash guy. I've always used functions and "onEnterFramage" to move things around and script. Over the last few months, I've been fooling around with NewBlacks custom Tween class he posted up for me and it seems to good to be true! Are there any drawbacks to compiling your swf files with an attached .as class file? Does the file need to be on the server or just in the directory when you compile? All it takes is one line of code to call the class, do some Penner movement, and then pass another function when movement is done. Seems too good to be true...I want to start doing it professionally and at work...but I am new to classes and 2.0, so I am a little concerned...
Built-in Functions
(Exciting new discoveries follow )
As you are well aware, most of built-in AS functions behave just as own-defined functions, meaning the following constructs will work just fine:
trace(Math.round); // output: "function"
a = Math.round;
b = a(23.1)
trace(b); // output: 23
b = a.apply(null, [23.2]);
trace(b); // output: 23
b = eval("Math.round").apply(null, [23.3]);
trace(b); // output: 23
However, there are exceptions.
1. The following functions do not return a function pointer. and therefore handling them as in the example above is impossible:
eval, getTimer, targetPath, getProperty, setProperty, chr, int, length, mbchr, mblength, mbord, mbsubstring, ord, random, substring, set, call, nextScene, prevScene, fscommand, print, printAsBitmap, printAsBitmapNum, printNum, stopAllSounds, toggleHighQuality, loadMovieNum, loadVariablesNum, unloadMovieNum
For example:
trace(chr); // output: undefined
a = chr;
b = a(65)
trace(b); // output: undefined
2. There are some functions that do return function pointer, but have some issues:
loadMovie, loadVariables, getURL, duplicateMovieClip, removeMovieClip, startDrag
loadMovie, loadVariables, unloadMovie, getURL:
- when used with apply() "get"/"post" values are ignored
- a="get"; loadMovie("movie.swf", _root, a); // won't compile
- a="get"; b=loadMovie; b("movie.swf", _root, a); // works fine
duplicateMovieClip, removeMovieClip, startDrag:
- this functions do return a function pointer, but it is useless. (Nothing done with it will work.)
Note that load/unloadMovie and load/unloadVariables won't work if you pass level for the second argument.
3. The following functions have issues when used with apply(). The thisObject passed must be a MovieClip or they will fail:
gotoAndStop, gotoAndPlay, nextFrame, play, prevFrame, stop
For example:
trace(gotoAndStop); // output: "function"
a = gotoAndStop;
a(23); // works
a.apply(null, [23]); // doesn't work
a.apply(eval(_target), [23]); // works
a.apply(this, [23]); // doesn't work when called from non MC object
That's about it. All other functions seem to work just fine, no matter how badly you try to misuse them.
FLVPlayback Built-In Functions Listing
I would really like to find a listing of all the things that I can call on a FLVPlayback
things like
FLVPlayback.play
FLVPlayback.pause
I can't find anywhere that lists them all and I am getting sick of looking.... anyone out there know where I can find one?
Also is it possible to populate an array with objects that are of type FLVPlayback and have a value of .visible = true;
What would that look like loosely? A get visible playback objects function?
Thanks... I am a total flash newb so sorry if some of this is obvious.
Need A Good AS Custom Built Scrollbar
Hi gang,
Ok, here's what I need, maybe somebody out there has one. I need a fully functional scrollbar that works with dynamic movie clips as well as hand-created ones. I need to be able to control the graphics of the scrollbar (to customize per job) and I need it in such a way that it's fairly easy to port and instantiate. Anhybody got any help out there? I've done one myself that half-works, but I figure why reinvent the wheel? Thanks everyone
Add Custom Methods For Built-in Classes
Hi
I know that I can create a new class that extends MovieClip, but is it possible to add custom methods to regular, built-in Flash Classes, such as MovieClip or Sprite?
Need Assistance With Custom Scrollbar I Built
I built a very simple scrollbar all on my own. I know there is lots of scrollbars in these formus but honestly wanted to see if I could make one by myself.
Well I did but I notice it's a bit skipy, not as smooth as others I've seen & was hoping for some insight.
This code resides directly on the dragger movieclip. The percent (this._y/195) I got from their being a possible 195 y position....not sure why, got it to finally work
I'd really appreciate some help.
Code:
onClipEvent(enterFrame){
percent = (this._y / 195);
_parent._parent.bioTxt.scroll = _parent._parent.bioTxt.maxscroll * percent;
this.onPress = function(){
startDrag(this,false,-18,-10,-18,195);
this.onMouseMove = function(){
updateAfterEvent();
}
this.onMouseMove();
}
this.onRelease = function(){
stopDrag();
}
}
Need Assistance With Custom Scrollbar I Built
I built a very simple scrollbar all on my own. I know there is lots of scrollbars in these formus but honestly wanted to see if I could make one by myself.
Well I did but I notice it's a bit skipy, not as smooth as others I've seen & was hoping for some insight.
This code resides directly on the dragger movieclip. The percent (this._y/195) I got from their being a possible 195 y position....not sure why, got it to finally work
I'd really appreciate some help.
Code:
onClipEvent(enterFrame){
percent = (this._y / 195);
_parent._parent.bioTxt.scroll = _parent._parent.bioTxt.maxscroll * percent;
this.onPress = function(){
startDrag(this,false,-18,-10,-18,195);
this.onMouseMove = function(){
updateAfterEvent();
}
this.onMouseMove();
}
this.onRelease = function(){
stopDrag();
}
}
Need Assistance With Custom Scrollbar I Built
I built a very simple scrollbar all on my own. I know there is lots of scrollbars in these formus but honestly wanted to see if I could make one by myself.
Well I did but I notice it's a bit skipy, not as smooth as others I've seen & was hoping for some insight.
This code resides directly on the dragger movieclip. The percent (this._y/195) I got from their being a possible 195 y position....not sure why, got it to finally work
I'd really appreciate some help.
Code:
onClipEvent(enterFrame){
percent = (this._y / 195);
_parent._parent.bioTxt.scroll = _parent._parent.bioTxt.maxscroll * percent;
this.onPress = function(){
startDrag(this,false,-18,-10,-18,195);
this.onMouseMove = function(){
updateAfterEvent();
}
this.onMouseMove();
}
this.onRelease = function(){
stopDrag();
}
}
Custom Events For Built-in Objects?
Is there any way to code custom events into built in objects?
A simple example of what I want to do is something like this:
create a method of the MovieClip object called "fade()"
at the end of the fade method (which would gradually drop the alpha), I want it to trigger an onFadeOut event. How do I do this?
Aaron
How Do I 'autoRewind' My Custom Built FLV Player?
I've been watching Lee's tutorials on Lynda.com. They're great. Specifically the ones about Flash 8 video playback. I just got finished watching the tutorials on building a custom FLV player.
Here's my question:
How do I get my video to 'autoRewind' once it's done playing?
It doesn't seem to be so simple without the FLVPlayback component :)
Thanks,
--Damon
How To 'auto Rewind' A Custom Built FLV Player
Lee,
I've been watching your tutorials on Lynda.com. They're great. Specifically the ones about Flash 8 video playback. I just got finished watching your tutorials on building a custom FLV player.
One question...
How do I get my video to 'autoRewind' once it's done playing?
It's not so simple without the FLVPlayback component :)
Could be a simple quick tutorial.
Thanks,
--Damon
How To Fade Out Video Controls Of Custom Built FLV Player
Hi there,
Firstly I would like to thank the creator of www.gotoandlearn.com for their indepth tutorials on how to build a custom flash player!
I have studied all the tutorials and have come up with the following custom built flv player:
http://www.watchlearnplay.com/watchi...estPlayer.html
I have now stumbled across a problem which I am unable to solve. What I want is for the video controls to fade out, when the user is not mousing over the player itself, thus giving the user a un obscured view of the video playing.
I cant for the life of me find a tutorial anywhere that shows me how to do it!
I am pretty sure that I need to take the video controls and place them in a separate movie clip, then have that entire movie clip fade in and out depending upon the users mouseover states.
Does anyone have any ideas on the best way to do this?
Regards
Jon
Extends To Built In Class-- Why We Do So
Quite often in our class we write
public class MyClass extends Sprite
public class MyClass extends XMLDocument
public class MyClass extends URLLoader
etc
How does it works in get executed in our program.Basically I know extending class denotes inheritance also we can use and call fields/variables and methods
of that class from subclass.But extending built in class .Does it means the same
Than how to implement functions of built in class from subclass.
can anybody help please .Thanks in advance
With Regards
Anurag
Best Way To Add Methods To Built-in Class
I have a flash application that requires some extensions to the Date an other classes. I currently do this like:
ActionScript Code:
Date.prototype.addMilliseconds = function(milliseconds)
{
this.setTime(this.getTime() + milliseconds);
};
This works fine but causes compile-time errors for a AS2 class that is bound to a movieclip, which uses these methods. The code works, I just get the errors when compiling. Presumably the compier isn't aware of my extensions because it compiles the movie clip class before my class extensions, which are in a seperate include, loaded in frame 1.
So i guess my question is, how can I get it to compile the extensions to Date class, before it compiles my movie clip classes, so that it'll know that these extra methods are available, and not give errors.
Thanks
Create A Subclass Of Built-in Class
I would say that creating a subclass of built-in class is possible, but how?...
For example:
Code:
format1_fmt = new TextFormat();
format1_fmt.size = 10;
format1_fmt.align = "right";
//
format2_fmt = new TextFormat();
format2_fmt.size = 15;
format2_fmt.align = "right";
Instead of defining a new format (format2_fmt) from scratch, because both formats have the same "align", I would like it to inherit the properties from format1_fmt
Overriding Built-in Sound Class
Hey there, I'm looking for some help with overriding the default Sound class constructor. I'm loading one SWF file into another using MovieClipLoader and sounds are not working. Apparently this is because when you create a sound with no argument ( new Sound() ), it will not play when loaded into another SWF. I do not have the source for the SWF that is being loaded.
What I need to do is create a new function which will pass in a default argument if one is not passed in. I got as far as to realize I need to use ASSetPropFlags, and I was able to override certain functions of the sound class such as start(), but I can't figure out how to fix the constructor.
Any help would be MUCH appreciated. Thanks in advance!
Getting Started With Built-in Display Class
Hello all,
I have a newbie question. I just installed Flash CS3 and I'm trying to get basic functionality working. I can't seem to display anything. It's recognizing the document class (Hello.as). I can trace messages in this class but just can't display anything to stage after addChild(). The app is recognizing the flash.display.* classes and flash.text.TextField class so the default classpath is correct. I get no compile errors. Just nothing displayed.
Here's my simple test class named Hello.as in the same folder as the launch.fla:
ActionScript Code:
package {
import flash.display.*;
import flash.text.TextField;
public class Hello extends Sprite {
public function Hello() {
var txt:TextField = new TextField();
txt.text = "Hello world";
txt.x = 60;
txt.y = 25;
addChild(txt);
}
}
}
I'm creating an instance of this class in frame 1 of my launch.fla with this script:
import Hello;
var a = new Hello();
I know it's a small newbie problem I'm just not seeing. Any advice appreciated.
TIA,
Michael
Getting Started With Built-in Display Class
Hello all,
I have a newbie question. I just installed Flash CS3 and I'm trying to get basic functionality working. I can't seem to display anything. It's recognizing the document class (Hello.as). I can trace messages in this class but just can't display anything to stage after addChild(). The app is recognizing the flash.display.* classes and flash.text.TextField class so the default classpath is correct. I get no compile errors. Just nothing displayed.
Here's my simple test class named Hello.as in the same folder as the launch.fla:
package {
import flash.display.*;
import flash.text.TextField;
public class Hello extends Sprite {
public function Hello() {
var txt:TextField = new TextField();
txt.text = "Hello world";
txt.x = 60;
txt.y = 25;
addChild(txt);
}
}
}
I'm creating an instance of this class in frame 1 of my launch.fla with this script:
import Hello;
var a = new Hello();
I know it's a small newbie problem I'm just not seeing. Any advice appreciated.
TIA,
Michael
UML Of Action Script 3 Built In Class
Hello All , I want to know where I can find the relationships between built in actionscript 3 classes ( the aggregation ,c omposition and ...) for example how LoaderInfo class is a property of FlashDisplay class ,is there any resource that shows the uml diagrams of builtin actiionscript 3 classes?
I aprrectiate you , sincerely yours Mohsena
Migrating From AS2 To AS3 (built A Class, But What About It's Image Etc?).
So I have now migrated my flash projects bullet movieclip code into a class, like so:
Code:
package
{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.*;
import String;
public class Bullet extends MovieClip
{
// Class wide variables.
var bmove:int = 1;
var b_name = this.name;
var t_bullet:String = b_name.substring(b_name.indexOf("_")+2, 20);
var o_tower:int = parent.target_array["bullet_"+t_bullet][0];
var etarget:String = parent["enemy_basic1_"+o_tower];
// Bullet class constructor.
public function Bullet():void
{
this.addEventListener(Event.ENTER_FRAME, enter_frame, false, 0, true);
}
// Bullet class, Enter Frame event.
private function enter_frame(Event)
{
if (this.DisplayObject.x < 0 || this.DisplayObject.y < 0 || parent.enemy_array[o_tower] < 1) { parent.removeChild(this) }
if (parent[etarget]._y < this.DisplayObject.y) { this.DisplayObject.y -= bmove; }
else if (parent[etarget]._y > this.DisplayObject.y) { this.DisplayObject.y += bmove; }
if (parent[etarget]._x < this.DisplayObject.x) { this.DisplayObject.x -= bmove; }
else if (parent[etarget]._x > this.DisplayObject.x) { this.DisplayObject.x += bmove; }
if (this.DisplayObject.hitTestObject(parent[etarget]))
{
parent[etarget].hp -= parent.target_array["bullet_"+t_bullet][1];
parent.removeChild(this);
}
}
}
}
Which as far as I know is fine, but it has no image, or any of the movieclip properties the original bullet did, how do I fix this? I still have my bullet movieclip on the stage, it just doesn't have any actionscript in it now (as I moved it to a class).
Am I supposed to somehow attach this movieclip (won't this cause bloat, the class itself extends a MovieClip type and then I go and add/attach a seperate MovieClip to it?).
P.S. If anyone finds anything wrong with the above class, feel free to let me know, it will certainly help (I have the class compiling without error but perhaps I might run into problems later down the track with some things), and those arrays are meant to be created in the frames onLoad event.
[F8] Problem With Using A Custom Class Inside A Custom Class
I'm getting this error:
Line 19: A function call on a non-function was attempted.
var a:Meter = new Meter(32,34,0x0000ff,0,0);
when I am trying to call a custom class (Meter) inside of another custom class, which I initialize in the main timeline. I can do this exact same line I copied above in the main timeline and it will work just fine, but not if it is used in the constructor of another custom class as I am trying to do. Any ideas on why this isn't working? Only thing I can come up with is that the class isn't imported at the time of the second class calling it but I've tried fixing that already.
Math Functions
hey guys, I'm from the FP forums, and I was just wondering what the Math functions are, such as Math.ceil(); etc.
sorry if this is old, or something, but I'm in a rush.
thanks!
PS. a link to a list would be preffered.
EDIT: I'm not sure which one to post this in, so I'm also posting it in the other actionscript section.
Math Functions
Could someone explain the math functions?
Code:
function drawCircle(mcClip:MovieClip, nRadius:Number):Void {
var nCurrentAngle:Number = 0;
var nControlX:Number;
var nControlY:Number;
var nArcX:Number;
var nArcY:Number;
mcClip.moveTo(nRadius, 0);
for(var i:Number = 0; i < 8; i++) {
nCurrentAngle = (i + 1) * Math.PI/4;
nControlX = Math.cos(nCurrentAngle - (Math.PI/8)) * (nRadius/Math.cos(Math.PI/8));
nControlY = Math.sin(nCurrentAngle - (Math.PI/8)) * (nRadius/Math.cos(Math.PI/8));
nArcX = Math.cos(nCurrentAngle) * nRadius;
nArcY = Math.sin(nCurrentAngle) * nRadius;
mcClip.curveTo(nControlX, nControlY, nArcX, nArcY);
}
}
Class Functions Not Able To See Other Member Functions/variables?
I am having a problem which has crept up on me a few times now. I am trying to call another member function within the same class, but Flash is unable to recognize it. This also happens when I try to read values of come variables.
For example, here I am trying to set the private boolean member variable to the state of the checkbox.
//NOTE: This is an EventListener. Does this change something major?
private function CheckBoxClick( evt )
{
_enabled = _root["test_sp"].content[_checkBoxName].selected;
trace( _checkBoxName + " checked: " + _root["test_sp"].content[_checkBoxName]._y );
}
This will output the following: "undefined checked: undefined"
Now in the function directly above it, I have the following function:
public function SetYPosition(pos:Number)
{
trace( _checkBoxName );
_root["test_sp"].content[_checkBoxName]._y = pos;
}
And this function will correctly output the checkbox name as well as update the position.
If I try adding the function call "SetYPosition(500);" to the first function (CheckBoxClick), the function will never be called as if Flash cannot see it.
In the past I have avoided this by using the global instance of the class such as _global.settings.function(blah), but the class I am working on now does not have a global instance.
Any ideas? This is really annoying!
Thanks!!!
Edited: 06/27/2007 at 03:30:12 PM by JoMasta
Can Anybody Explain The Math Functions?
What I mean is, the functions that can be used after "Math.", like PI and Round.
I feel bad asking for so much, I wrote down all of the terms I want to be defined, so you wont have to do so much work. I filled in the few that I knew
Math.abs
Math.acos
Math.asin
Math.atan
Math.atan2
Math.ceil
Math.cos
Math.E
Math.exp
Math.floor
Math.LN2
Math.LN10
Math.log
Math.LOG2E
Math.LOG10E
Math.max
Math.min
Math.PI - 3.14...
Math.pow - Power
Math.random - Generates random number
Math.round - Rounds off a number to the nearest whole number
Math.sin
Math.sqrt
Math.SQRT1_2
Math.SQRT2
Math.tan
Thank so much!
Variables In Math Functions.
Hi all,
I was wondering if anyone can help.
In my flash movie the follwing code works fine:
_root.num = random(10);
_root.holder.box.text = eval ("_root.content_"+num);
Basically this code creates a random number which is then added to "_root.content_" to randomly select some text for a dynamic text field.
However, rather than defining the upper limit of the random selection with a number (ie 10), I want to pass in a variable from a text file (_root.value). The code that I am using is:-
_root.num = Math.floor(Math.random()*_root.value);
_root.holder.box.text = eval ("_root.content_"+num);
But this does not work. NaN is being returned.
Any help would be really appreciated!!!
Thanks,
Maw.
Exotic Math Functions
I'm using math functions to create paths for the enemy spacecraft in my game and was wondering if anyone knew any interesting math functions which produced strange graphs which I could use as flight paths across the screen.
Math Functions In Flash.
A have a little problem using math functions with AS.
Some of them work, some don't, and i can't understand why.
Here's an example:
y=x+2 -- this._y = this._x +2 -- this one works
y=x^2+2x+15 -- this._y= this._x^2 + this_x*2 + 15 -- dosen't works
It is strange, does anyone have an idea how to use this kind of functions with the help of AS?
Can Flashs Math Functions Get The Cos And Sin Of Dregees?
I was looking those the other day, but it appeared that flash's built in math funtioncs take the cos and sin and turn them into radians. I want to take degrees and turn them into cos and sin. Is there a way to do this or do I have to hard code many a number into my lil 3d engine?
Can You Achieve Math Functions With Actionscript?
I want to put a mortgage calculator inside a flash file but don't know how to re-code this page in actionscript. I need math functions in a big way...
Anybody know the best way to achieve this?
It needs to work similarly to this page...
luxurymountainproperties.info/calculator.html
Is There A Reference For Math Physics Functions
Hi everyone,
I am trying to figure out the math behind scaling an object based on mouse distance from the object. I was not a math major and I am wondering if there is a place where people post code to do certain mathematical operations. A book or a website or something?? Knowing the math behind these operations is a major hurdle for me to overcome!
As for my example, I want to scale an object up a little as the mouse gets closer to that object.
Thanks for your help!
-Brian
Why Are The Math Functions So Insanely Slow?
ActionScript Code:
import flash.utils.getTimer;var n:Number = 1.5;var st:Number = getTimer();var test:int;function divT():void { st = getTimer(); for(var i:int=0;i<10000000;i++) { test = Math.floor(n); } trace("Time spent calculating with Math.Floor: " +(getTimer()-st)+ " ms");}function divB():void { st = getTimer(); for(var i:int=0;i<10000000;i++) { test = int(1.5); } trace("Time spent calculating with conversion to int: " +(getTimer()-st)+ " ms");}divT();divB();
Whereas I see and understand the results, I don't get why the built in floor function is so incredibly slow compared to int conversion.
Can anyone shed some light on this?
Tween Class If Moved Mc Passed Point Start Another Tween
Hey Actionscript Gurus
Now I am using the Tween Class to move some boxes in my movie, now I can move the first mc and then another mc after the first tween has finished with onMotionFinished but I was hoping someone could help with how do I start the second tween when the first mc has passed a certain _x coordinate.
ie starting the second mc moving while the first tween is still moving.
I am trying to do a intro loader for my front page controlling around 7 boxes. So I need to repeat this a few times.
Regs,
Jacko
Tween Class If Moved Mc Passed Point Start Another Tween
Hey Kirupa Flash Gurus
Now I am using the Tween Class to move some boxes in my movie, now I can move the first mc and then another mc after the first tween has finished with onMotionFinished but I was hoping someone could help with how do I start the second tween when the first mc has passed a certain _x coordinate.
ie starting the second mc moving while the first tween is still moving.
Regs,
Jacko
|