ActionScript 1/2 :: Multiplying An Instance?
May 6, 2009I have an instace of a coin on a table and I want to make it multiply and stack
View 3 RepliesI have an instace of a coin on a table and I want to make it multiply and stack
View 3 RepliesI have this mc that responds to mouseX , only the mc is very short in frames, it's only 25 frames long. This way the mouseX is only the first 25 pixels of my stage, so it only responds to that. Is there any way I can multiply this value to, let's say, 20 times?
View 1 RepliesI have this code:
[code]....
It is called recursively. The problem is the alpha value augments, apparently multiplying itself. Why? I successfully remove the child.
Was wondering if there is a script that can mutiply objects over the time line.So for example if one rock appears in frame 1, and then a 2nd rock in frame 2and a 3rd rock in frame 3, etc,But say starting on frame 4, six rocks would appear, and on frame 5, twelve rocks would appear...so that the rocks would appear exponentially for example.The numbers or accuracy does not matter, its more about displaying a number of rocks much faster along the time line, instead of 1 rock/frame.
View 1 RepliesI have the movie clip "movie" in my library and the button "btn" on the stage.Now everytime I release "btn", I want to add "movie" to the stage and have it play from predetermined coordinates (let's say _x = 20, _y = 20)...So far, I've tried
Actionscript Code:
on (release) {duplicateMovieClip("movie", "movie2", 1);}
but that doesn't do the trick because it doesn't multiply the displayed movies.Everytime you release "btn", "movie" breaks off and restarts,I want it to finish its animation and have ANOTHER one spawn at the origin...
When multiplying a floating point number that is very close to 1 with an int > 0, can it ever be interpreted as 1.
That is, if Math.random() returns its highest possible result (which is 1 step below 1.0), will
(int)(Math.random() * 8)
be 8 or 7?
For a practical example, can this often-used construct give an index out of bounds error:
someArray[(int)(Math.random() * someArray.length)];
I'm specifically interested in answers for Java and ActionScript 3, but I suppose they all use the same rules for floating point arithmetic, and answers for any platform would be useful.
Update: Though I already accepted an answer, I'd still appreciate confirmation that this can't go wrong in ActionScript 3 either, since a colleague reporting that he saw it go wrong once is what partly prompted me to ask this question.
Strange problem, least I think it is I just can't work out how to multiply two text boxes and then display it in another text box. I have tried the following but had no luck should these work thus some other code is messing it around or would non of these work;
box1.text = box2.text * box3.text;
box1.text = number(box2.text) * number(box3.text);
In my page i use animated swf for button. And at the moment page knows how many buttons there needs to be via category nodes in xml so i made a loop to load in the right number of same swf-s. Is there a bettery way to do that like load swf only once and than duplicate it via script? Or something else i did not think of?
View 1 RepliesIn my page i use animated swf for button. And at the moment page knows how many buttons there needs to be via category nodes in xml so i made a loop to load in the right number of same swf-s. Is there a bettery way to do that like load swf only once and than duplicate it via script?
View 4 RepliesI have a function that adds the values of an array together and displays the output in a textArea(myText).
The code below works fine, but the output number is "11.5" I need this to be "11.50" and again if we set the array index [1] to "0" instead of ".50" I would need to show "11.00" instead of "11" which is what I am getting now!
var myArray:Array = new Array(1.50,.50,0,9.50); function addValues(myArray:Array):Number{ var arraySum:Number = 0; for (var i:uint=0; i< myArray.length; i++){ arraySum += myArray[i]; } return arraySum } trace(addValues(myArray)); myText.text = String (addValues(myArray));
I am doing the following in actionscript in Coldfusion Flash Forms:
90 / 3.7
Gives me:
24.3243243243243
Whereas the calculator gives me:
24.32432432432432
Note the extra 2 at the end.
So my problem occurs when I am trying to get the original value of 90 by taking the 24.3243243243243 * 3.7 and then I get 89.9999999999 which is wrong.
Why is Actionscript truncating the value and how do I avoid this so I get the proper amount that the calculator gets?
In my page i use animated swf for button. And at the moment page knows how many buttons there needs to be via category nodes in xml so i made a loop to load in the right number of same swf-s. Is there a bettery way to do that like load swf only once and than duplicate it via script?
View 2 Repliesi would like to basically represent a group of cells multiplying and dyeing. I have some data im pulling in, from an xml file and would like this to generate some cells. I have figures that change frequenly, so for example, if the figure increases i would like the cell to multiply and if the figure decreases i would like cells to die off.
If any one point me in the direction of some examples or give me some ideas about the best way to do this i would really appreciate it.
As you can see im not sure if i should be looking at flocking or recursion etc so
I am trying to calculate the values on user entered text fields (which only accept numbers) along with the values of user selected combo boxes. I have a function to a button:
reviewQ.calcBtn.addEventListener(MouseEvent.CLICK, calcAns);
function calcAns(e:MouseEvent):void
{
reviewQ.calcAns_text.text = "Your calculated result is " +
[Code]....
Right now, all I am getting is the actual values entered in the text fields and selected in the combo boxes. How can I get the sum of this values to show on my "calcAns_text.text"?
Does creating a new instance of an Object that uses an identical name to an older instance, delete the previous instance? Or should the original instance be deleted first? The code uses a ridiculous amount of XML vars. Isn't it less memory intensive to parse the XML and save the properties to an Object, and then delete the XML Object, rather than keep the XML Object around and reference it's child nodes directly? Is it better form to break up a huge XML file (>600lines/3200vars) into smaller chunks?
View 1 RepliesI have a library object (SomethingMC) which extends a custom class (Something). Something, in turn, extends MovieClip.If adding SomethingMC to the stage within Flash CS3 IDE, is it possible for it's super class (Something) to assign an instance name from a class constant (Something.THE_CONSTANT)?
package
{
import flash.display.MovieClip;[code].....
The above does not work. It throws Error #2078: The name property of a Timeline-placed object cannot be modified. if the instance is assigned a name in the IDE, and it just doesn't work if no name is assigned in the IDE.
I have a BUNCH of bumpers of four types bounceUp, bounceDown, bounceLeft, bounceRight. during a collision which you hit determines the bounce so they always do the same thing so here's my question.....can i just name every bounceUp instance the same thing and then just add that one instance name to the list the collision detector checks?
i just dont wanna go through and name a hundred each of bounceUp s and bounceDown s individually as the potential for screaming increases proportionally.......
I placed a movie clip instance inside a button, and I want this movie clip to play when the button is released. I'm using this code on the frame containing the button:
function playMovie(event:MouseEvent)
{
this.theButton.theMC.gotoAndPlay(3);
[code].....
Does anyone know if it is possinle to scroll a graphic or a movie instance as well as a text instance in flash. I want to scroll text and images as well. Actually text with imges embedded in it.
View 3 RepliesI am wrapping my brain around OOP in AS2. I am making two posts on two different subjects. My question here is: when should I use local instance variables, and when should I attach new properties to the instance object? (Feel free to correct my terminology.) Let's say I have a class for a scrolling background, which scrolls when I mouse over its edge. I want to put these values somewhere:
1) How wide is the border in which a mouseOver makes it scroll? This is basically a semi-constant I set it up once and keep it the same, unless the user changes it in an options menu to make the border wider or narrower. Call this scrollBorderWidth.
2) How fast is the background scrolling now? I want to track this so I can smoothly change the scroll speed over several frames. This is often changed. Call this scrollSpeed.
It seems I have two ways I can store and access these values and darned if I know which is better practice. METHOD A: Make them local variables in the class, so the scrolling background instance has them as local vars. I set them up thusly:
[Code]....
I have a general / somewhat newbie question. Is it better practice to call a function from another class like so:
[Code]...
Does one way free up more memory or enhance performance?
I have a base class I've used on 6 different MC's. Then when I use these MC's my function runs an if statement to check which one to add.
if(id=design) var obj = new design();
if(id=team) var obj = new team();
I want to make it a bit more dynamic and use the id:String to evaluate which new instance to create.
ActionScript Code:
public function loadChapter(id:String):void {
var obj = new instance_of( id )();
}
I have a bunch of text boxes which are acting as labels on a diagram.The idea is all the labels are jumbled up to start with, and the user has to drag the labels to the correct place.So far, I have the labels, and they are dragable, but I want to be able to lock the label onto a specific area (I've called them crashzones) so that when the user drags the label onto the correct area, the label snaps into place.The 'crashzones' instance names, are indentical to the label instance names, with the exception that the 'crashzones' instance names have the letter 'z' at the begining.
On the dragStart event, something (maybe a string) would hold the instance name of the current label and add the letter 'z' to the beggining, so something like ... crashzone = "z" + label1;As there is an instance with the name "zlabel1", when the dragstop event starts, it'll do a 'hittestobject' on the instance "zlabel1".
I'm not entirely sure how to go about this.I've tried creating a string to hold the 'crashzone' name, but the hittestobject event doesnt work with strings i.e: hitTestObject(stringname);I've also tried with Sprite, but as the sprite technically already exists and has a name, I can't give the sprite any properties.
I have a base class which is being created via remote_object [RemoteClass alias] from the server.I have other specialized classes that are derived from this baseclass, but serialization with the server always happens with the base class.The base class has meta data that defines what the derived class is, for example
[RemoteClass (alias="com.myco...')]
public Class Base
{
[code]....
I am trying to communicate between an instance of flash embedded in a browser and a flash instance running in a C# WinForms app... I am getting a compile error that say:
1119 Access of possibly undefined property printOut through a reference with static type flash.net:LocalConnection
Here is the actionscript:
var feedback = "";
var receiving_lc:LocalConnection = new LocalConnection();
receiving_lc.connect("fromClient")
[code]....
I'm using a library that has a function that returns an instance of some class Engine.
I'd like to tack on some interfaces to Engine, so I subclass it class InterfacedEngine extends Engine implements AwesomeInterface. but when I change the code that uses the classes from this:
var engine:Engine = generateEngine();
to this: var interfacedEngine:InterfacedEngine = generateEngine();
It gives me a runtime error (elision mine):
TypeError: Error #1034: Type Coercion failed: cannot convert ...::Engine@1bc2bf11 to ....InterfacedEngine.
What about AS3 classes am I misunderstanding?
I have to admit I pretty much ran away from Flash when AS2 came along and only used it for animation purposes over the last 5 years.So I'm having a major crash course in AS3 in Flash CS3 and I'm not enjoying it one bit. I'm getting maybe 10mins of finished work per hour as I try to figure out the limits and rules of AS3. Quite often it seems that AS3 simply can't do what I want it to. Anyway: Characterchecks.as is the main class and it loads a bunch of XML into four arrays. The file starts like this:[code]If I trace the value of, say, cc._Categories from the main FLA, it's empty. I'm guessing that the next line of AS in the main FLA doesn't wait for the previously called function to complete? (This may tie in to my next problem)My next step is that I want to display various things based on the data in the array. I have another class, Display.as which will hold all the functions to create the items on display. I thought it would be best for these to be a separate object. I wonder if I'm right?
So I declare an instance of Characterchecks in the main FLA and call it cc, and then run the functions to populate the arrays... Now I create an instance of Display and call it cd. How can I get functions in cd to see the values of the variables in cc? And if the main timeline can't tell that the functions aren't finished filling the arrays, how is cd supposed to know?I might be asking dumb questions, or maybe I'm doing things ***-backwards, I don't know. I'd appreciate any help, I really would. This whole thing has me at the end of my tether... being the most technically advanced person in my circle of co-workers and web design friends means I have no-one to explain why things need to be done a certain way or what the best way is.
I'm creating a little game - The player controls a character that follows the mouse. Pigs run away from the player, and the player has to get them all into a pen. To make the game a little more difficult I'm trying to add an enemy - wolves, that attempt to perform a 'hunt' method every x seconds. This method sends a reference of the wolf instance to Main (my document class) and Main then loops through the pigs on stage to see if there's any nearby. Now as far as I know this works - my problem is I'm unsure how to send the pig instance reference back to the wolf that called the hunt method, so it can then 'target' the pig, and then attempt to pounce on it.
This is my Wolf class:
Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
[Code].....
how do you do this...if (you rollover instance 'imgsmall' ) then
display visible instance 'imglarge' then
rollout (instance 'imgsmall') then do not display 'imglarge'
I have a whole bunch of movie clips within a single movie clip. I want to trace exactly which instance-within-instance was selected when the user clicks on the outer movie clip. In other words I need Flash to return the instance name of the Movie Clip I just clicked on.
View 4 Replies