Help Required For Calculator Actionscript Using Arrays
Hi, i'm a newbie in actionscript and started not just long ago. Does anyone knows how to create a flash calculator using arrays? any clues anyone? Thanks
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 07-19-2007, 11:25 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Actionscript Pro Required: Syntax Help Required For Button To Initiate Easing
Hi guys I was wondering if any of you actionscript daddio’s could give me 2 minutes of your time and help me write the appropriate syntax to make the below example work on a button release rather than on the MC mouse down state that it currently uses.
http://www.fluid.com/experiments/timecode/mx_time.html
If you click on the geek panel drop down menu, you will see that it generates the appropriate code for the on onMouseDown,, however I want to call the easing from a button.
If someone could give me an example of the correct syntax using the “easeInquad” function that would be brilliant.
Arrays Help Required..
Hi All..
I have one serious problem..
I created an array MyArr where MyArr[0]=01-01-06 MyArr[1]=1.pkg MyArr[2]=2.pkg MyArr[3]=3.pkg MyArr[4]=4.pkg
Now I must check whether a particular element is present in the array or not..!
So I wrote a if loop saying if(contains("1.pkg",MyArr)==1) display saying yes it is there..or else display saying no..
But my code is creating me problems..Can anyone explain me by writing an action script code ??
Thanks
Nirmal.
ActionScript Calculator
I recieved an email this morning asking me about building a calculator in flash.
Here is the email:
Quote:
hey i need some help plz (with actionscript)
how do i make a calculator?
can u write step by step plz
(and by the way i'm <...>
an i got ur addy form a forum)
You might be thinking that he was quite rude about it. I certainly did and my reply email said that a lot and then as not to be too rude, I actually tried to help the guy out.
You might be thinking that this is very nice of me, but you didn't read the reply
I don't know where he got my email from, it might not have been from this forum but I thought that I would post it here anyway.
If you spot any bugs, please post about how to recreate them.
Preview here: http://img100.imageshack.us/my.php?i....swf&width=320
You'll notice I chose to use the mathematical approach over the more simple Number(string) approach. Makes things more exciting !
ActionScript Code:
/* SETTING UP THE STAGE To set up the stage I created buttons for the following actions (with their relative instance name in brackets) -------------------------------------------- Button Instance Name Action -------------------------------------------- 0 input_0 0 1 input_1 1 2 input_2 2 3 input_3 3 4 input_4 4 5 input_5 5 6 input_6 6 7 input_7 7 8 input_8 8 9 input_9 9 . action_point Start adding to decimals = action_equals Calculate Answer + action_add) Add the new number - action_subtract Subtract the new number * action_multiply Multiply the new number / action_divide Divide the new number C action_clear Clear the current input CE action_clearall Clear the current solution 1/-1 action_state Changes the current input between +/- it's value -------------------------------------------- And then I created a textfield with variable property set to "output" This means that the textfield I created will display whatever is in the variable `output`. There is also a textfield with variable property set to "action" to show the current method being used.*//* VARIABLES*/ // The contents of this variable is shown in the textfield var output:String = ""; /* The following variables are used to calculate the effect of inputing a new number. I'll talk a little about the mathematics behind it. When we want to add a number to the end of a new number, for example: 123 becomes 123, we multiply our original number (123) by 10 and then add the new number (4). When we want to add a decimal to the end of a new number, for example: 123.4 becomes 123.45, we multiply the new number (5) by 10^-(# decimal places). However there are no calculaations required for this. The method we will assume will update the multiplier of the new number with every number after the decimal point that is added. Upon each update of this multiplier, the multiplier is divided by 10. The variables are currently set up for appending new numbers to the end of the the current number When the point button is pressed they are changed to reflect their new requirements */ var multiplier_old:Number = 10; var multiplier_new:Number = 1; // This variables shows that the point buttons has/hasn't been pushed var point:Boolean = false; // This variables stores what action we're going to take when we update, whether it be +,-,* or / var action:String = ""; // The current solution (updated with every new action submitted) var solution:Number; // The current number in the textfield var input:Number = 0; // The current input's state (positive / negative); var state:Number = 1;/* BUTTON ACTIONS Each input button will call a function with it's relative number, to avoid having to copy and paste all of the working code.*/input_1.onPress = function() { inputNumber(1); }input_2.onPress = function() { inputNumber(2); }input_3.onPress = function() { inputNumber(3); }input_4.onPress = function() { inputNumber(4); }input_5.onPress = function() { inputNumber(5); }input_6.onPress = function() { inputNumber(6); }input_7.onPress = function() { inputNumber(7); }input_8.onPress = function() { inputNumber(8); }input_9.onPress = function() { inputNumber(9); }input_0.onPress = function() { inputNumber(0); }// =: Runs the calculation function. the `true` parameter tells the function to unset `solution`action_equals.onPress = function() { calculate(true); };// .: Sets the multipliers so that new input numbers become decimals of a lower unit columnaction_point.onPress = function() { multiplier_old = 1; multiplier_new = 0.1; point = true;};// 1: Changes the state between 1 and -1;action_state.onPress = function() { state *= -1; }// *: Each button of type +-*/ calls the setAction function with the appropriate symbol for their actionaction_add.onPress = function() { setAction("+"); };action_divide.onPress = function() { setAction("/"); };action_subtract.onPress = function() { setAction("-"); };action_multiply.onPress = function() { setAction("*"); };// C: Clears the current input for use in the event of a mistake being input. Basically just resets the variablesaction_clear.onPress = function() { input = 0; point = false; multiplier_old = 10; multiplier_new = 1; state = 1; output = input.toString();}//CE: Same as C but clears the solutions and actions - total reset. Calls the action_clear.onPress function instead of copying in the code again.action_clearall.onPress = function() { solution = undefined; action = ""; action_clear.onPress();}// Takes intput from the input_ buttons and adds it to the input after applying the multipliers in the method described above.// If `point` is true then the multiplier_new is divided by 10, also as described.function inputNumber(n:Number):Void { input = input*multiplier_old + n*multiplier_new; if (point) multiplier_new *= 0.1; output = input.toString();}// Sets the current action in the `action` variables.// The call to calculate() simply updates the input and solution variables (more in the calculate function explanation)function setAction(a:String):Void { calculate(); action = a;}/* CALCULATE FUNCTION This function calculates how to update the solution. If there currently is no solution, ie. this is the first time that an action button has been pressed, then the solution is simply going to be the input and is set accordingly. When there is already a solution specified, ie. this call is after the first call - something has been updated, then the solution is updated according to the action. After either of these events, the solution is put into the output display and then variables are reset for the next input's usage.*/function calculate(end:Boolean):Void { input *= state; if (solution == undefined) { solution = input; } else { switch(action) { case "+": solution += input; break; case "-": solution -= input; break; case "*": solution *= input; break; case "/": solution /= input; break; } } output = solution.toString(); input = 0; point = false; multiplier_old = 10; multiplier_new = 1; state = 1; action = ""; if (end) solution = undefined;}
Hope this helps somebody.
The FLA is in MX2004 format.
[CS3] Risk Calculator (Actionscript 2)
So I have been working on a calculator to help me calculate medical risks for patients. This will ultimately be a small part of a larger calculator, but I need to get this working first. I have an interface which has a drop-down for a Vessel Diameter. And there are also checkboxes to account for additional risks. What I want to do is have a "Total Risk" box dynamically reflect the changes from the drop-down and the clicking of the checkboxes.
So far, I have assigned a boolean value to the checkboxes, as well as a data value. The drop-down box has values as well (including a multiplier). But with the event listeners applied to each, the text doesn't update dynamically, and if you uncheck a checkbox, the "Total" does not reflect that change.
I finally got to a point where I could make sense and ask a somewhat intelligent question now. Still an actionscript noob, so be kind =). Any assistance would be greatly appreciated!!!!
Thank you all!
Pete~
Help Required Again......actionscript
ok
problem
i want to allow the user to exit the cd-rom from the exit button ...back to normal setting of their pc? is this to do with unloading movies ? anybody out there who can point me to good source files/ tutorials please help
also i want the swfs to fill the pc screen ( i do not know the correct wording for this projection maybe?) anyone out there can let me know
thanks again to all who have helped so far......
please help again if youse can !
J
Actionscript Help Required.
Hi,
I am having problems with actionscript. I am trying to create a 360 degree panaroma. I am using this tutorial provided.
http://www.flashkit.com/tutorials/Sp...h-51/index.php
As this tutorial is written for a previous version (i am using MX),
Set property is defined as below.
,
Set Property ("/movie2", X Position) = GetProperty("/movie1", _x) + 3557
Set Property ("/movie2", Y Position) = GetProperty("/movie1", _y)
I have changed this to match actionscript specifications.
setProperty("/movie2", X Position, getProperty("/movie1", _x+2809));
setProperty("/movie2", Y Position, getProperty("/movie1", _y));
Unfortunatly, I still get this output script error
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: ')' or ',' expected
setProperty("/movie2", X Position, getProperty("/movie1", _x+2809));
All of the set property commands throughout the script return errors. Is there a problem? I have tried placing ')' or ',' as the problem suggests but cannot find a solution. Please help me if you can.
Thanks a lot
KBFM
Actionscript Help Is Required, Please.
Right.
So I'm making a new flash website, and I need some AScripting help. I have a few problems.
1. Content. The main content box is supposed to load external SWF files (e.g. home.swf, aboutme.swf) into the space there. The external SWF files are basically just SWFs which load external text files (e.g. home.txt, aboutme.txt) that contains the real content. Right now, I have managed to get the external SWFs to load the text files, but for the life of me I cannot get the main movie to load the SWFs into the content box. I know it's ****ing loading, because the external SWF has a preloader, and the preloader appears, but once it finishes loading, nothing else appears, though when I put my mouse over it, it turns into a text highlighter cursor, so I know it must have at least loaded SOMETHING. What exactly is wrong with my code?
2. Scrollbars. Notice the scrollbars on the side of the content box? Good. How do I make them actually work? I really have no clue as to how to go about doing this. I've been looking at scrolling tutorials, but I haven't seen one which actually allows both a slider and buttons.
3. Quick News Box. Is it possible to make a external SWF transparent except for the text? I want to be able to load external text files into that news box, but I don't want the SWF's background to be white or anything, just transparent. Is this possible?
4. Navigation. The way my navigation bar is like is, well, it's just a single bar, not seperated into individual links. Would it be possible to create invisible "hitboxes" that act as the areas for the users to click?
Attached is the entire directory of my site for reference. Could anyone of you guys just like, you know, work some Ascripting magic and get it to run? Or at least linky to some specific tutorials?
- Current SWF preview of the site done so far: http://img231.imageshack.us/my.php?image=cutout27wy.swf
- Current home.swf file preview: http://img231.imageshack.us/my.php?image=home8vw.swf
[b]UPDATE: Do note that the previews are ****ed up, because they can't reference each other and there's no home.txt available.
ZIP file of entire site here:
http://files.filefront.com/CutOut2zi.../fileinfo.html
Actionscript Help Required
Hi. I am building a kind of screen show. I have several slides which change automatically. I also have down the side, a list of slide titles. Clicking one of these titles changes the slide accordingly. This all works great.
The problem i have is, the file also contains sound which is synchronised to the time line. therefore, downloading the entire file is a little slow. If i click one of the slide titles, and that part of the file has not yet downloaded, nothing happens.
I figured, the best thing to do was to hide all the buttons to start with, then as the movie progressively downloads, the slide titles slowly become visible, one at a time.
To achieve this, i have created a movie, and placed the following actionscript in it. (The Slide Title buttons are in another movie called "slideTitles", and the _root timeline has labels "Slide1", "Slide2", "Slide3" etc
Code:
onEnterFrame = function(){
if (_root._framesloaded >= eval("_root.Slide"+_root.firstSlide)){
eval("_root.slideTitles.btn_slide" + _root.firstSlide).enabled = true;
eval("_root.slideTitles.btn_slide" + _root.firstSlide)._alpha = 100;
_root.firstSlide++
}
if (_root._framesloaded >= _totalframes){
delete onEnterFrame;
}
}
This did not work. All the slide titles were visible in frame 1
What am i doing wrong?
Actionscript Help Required
Hi. I am building a kind of screen show. I have several slides which change automatically. I also have down the side, a list of slide titles. Clicking one of these titles changes the slide accordingly. This all works great.
The problem i have is, the file also contains sound which is synchronised to the time line. therefore, downloading the entire file is a little slow. If i click one of the slide titles, and that part of the file has not yet downloaded, nothing happens.
I figured, the best thing to do was to hide all the buttons to start with, then as the movie progressively downloads, the slide titles slowly become visible, one at a time.
To achieve this, i have created a movie, and placed the following actionscript in it. (The Slide Title buttons are in another movie called "slideTitles", and the _root timeline has labels "Slide1", "Slide2", "Slide3" etc
Code:
Code:
onEnterFrame = function(){
if (_root._framesloaded >= eval("_root.Slide"+_root.firstSlide)){
eval("_root.slideTitles.btn_slide" + _root.firstSlide).enabled = true;
eval("_root.slideTitles.btn_slide" + _root.firstSlide)._alpha = 100;
_root.firstSlide++
}
if (_root._framesloaded >= _totalframes){
delete onEnterFrame;
}
}
This did not work. All the slide titles were visible in frame 1
What am i doing wrong?
ActionScript Required
Hi All,
Your assistance will be highly appreciated…
I would like to have the AS to put on a button to do the following:
on (release) {
_root.link = 6;
Duplicate the movie therein;
Replace a clip in the movie (clip on stage) with clipnew (from the Library) – Note: These are scrolling texts;
Play the new movie;
}
Thanks a lot.
Some Actionscript Help Required.
Ok guys. Im making a Dawn of War flash game. In this game you pilto a space ship and the game is sort of like Raiden, where the enemies fly down the screen at you.
Now i need some help with the actionscript coding.
So far ive drawn up my ship, the ships bullets, and a green circle for actions. The green circle is not visible though. The ship's instance-name is "mc_ship", the bullets instance-name is "mc_bullet", and the actions circle istance-name is "mc_actions".
So here is the code i have so far.
On the bullet(mc_bullet) --
///////////////////
onClipEvent (enterFrame) {
var firing = false
}
On the ship(mc_ship) --
///////////////////
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y-=15;
}
if (Key.isDown(Key.DOWN)) {
this._y+=15;
}
if (Key.isDown(Key.LEFT)) {
this._x-=15;
}
if (Key.isDown(Key.RIGHT)) {
this._x+=15;
}
if (Key.isDown(Key.SPACE)) {
firing = true
}
}
On the invisble circle(mc_actions) --
///////////////
onClipEvent (enterFrame) {
this._visible = false
if (firing = true) {
mc_bullet._y = mc_ship._y+40
}
}
////////////////////////////////
OK so what happens so far is you can move the ship around with the arrow keys, and that works fine, but now i need to know how to make it shoot. Ive tried so much different code, but none of it seems to work. Ive gone close experimenting with my own knowledge of the code, but now ive turned to you guys.
The movement works fine, its just the shooting I need help with. I also need to know how i can make it work without completely changing my code. But I will do it all over again, only if neccessary.
Thanks for any help.
(BTW, I didnt use attach code, because I just signed up to these forums and I copied the code straight from one of MY other posts on another forum.)
ActionScript Genius Required
I am loading in a MC and I want to pass it an object full of data. The object is almost passed.
I did a trace using:
Code:
function show_all(temp) {
for (i in temp) {
trace(i+" = "+temp[i]+" {}");
for (j in temp[i]) {
trace(i+"."+j+" = "+temp[i][j]+" {}");
}
}
}
The (expletive deleted) is there. But there is no data in it. My trace is:
Code:
happy = {}
joy = {}
When it should have been more like:
Code:
happy = [object Object] {}
happy.happy = Joy joy {}
joy = Joy {}
Can anyone help?
Actionscript Error - Help Required
Hi
I picked up an old flash file recently - probably coded in flash 5
but i use MX and when publishing I get the following error:
Code:
Symbol=Symbol 105, Layer=Action Layer, Frame=1: Line 32: ';' expected
_n2.maximum_word_length = -1.#INF00E+000;
The code around that line is:
Code:
var _n2 = this;
_n2.a_list = new Array();
_n2.maximum_word_length = -1.#INF00E+000;
Now I asked the guy I got it from and all he could tell me was that
-1.#INF00E+000
Is probably part of the old action scripting and ill have to find the new alternative
Is this true and if yes what would be the "new" substitute for the above?
Thanks
ActionScript Smarty Pants Required
Why would:
xspeed = 10;
_x += Number(xspeed)
work to move an object across the x axis but:
fade = 10;
_alpha += Number(fade)
not work to fade the object in?
If I word like this:
_alpha += 10
it works! But then I can't stop it with an if statement when the alpha value reaches 100 or 0.
HELP!
Mobile Buttons Actionscript Required Help
Hi All
Is this possible ???????
i have an image of a mobile and i want to show the interface working.....therefore the two butons on a mobile that allow the user to scroll through the options and then another button that is clciked to bring the user to a specific screen
Anyone got any good source files on this
or tutorials
help urgetnly needed
thanks
J
URGENT Actionscript Hero Required
hi, a small yet urgent challenge for any actionscript heros:
imagine a cake, choped into 10 slices, viewed from above. my goal is to have this cake rotating at a constant speed until the user clicks on one of the slices. if a slice is clicked on i would like the cake to speed up and rotate a certain amount so that the selected slice is at 11 o clock, and then the cake stops rotating.
i've made a 60% working version but i'm getting bogged down now and progress is becoming slower... i'd love someone to show me a nice optimal way of doing all this (i'm not scared of maths, its just flash timelines etc that screws me up), any help'd be greatly appreciated, taaaa.
Urgent Flash Actionscript Help Required
hi
i have a handin on wednesday so its vital i get this fixed.
I have a menu system that magnetically draws itself to mouse when the mouse is on the x axis in alignment to each button. i need help in putting possibly an if statement which will stop the menu from going all the way across the screen, and only going, lets say around 375 pixels on the x before stopping, or even better would be if the buttons only moved when the mouse was in a 100 pixel radius. I want to implement this as the current structutre is annoying if the mouse is on one side of the screen, and the button flies across even though i dont want it to, and it ends up obscuring the movie clip which is playing.
Heres the code
onClipEvent (load) {
name = "button title";
Button = 1;
ratio = .3;
left = _root.left;
right = _root.right;
}
onClipEvent (enterFrame) {
o_x_pos = _root.button1_x;
o_y_pos = _root.button1_y;
mag = _root.magnet;
if (_root._ymouse>(o_y_pos-mag) & _root._ymouse<(o_y_pos+mag) & _root._xmouse>left & _root._xmouse<right) {
this._x = x_pos;
x_pos = x_pos-(n_x_pos*ratio);
n_x_pos = x_pos-_root._xmouse;
this._y = y_pos;
y_pos = y_pos-(n_y_pos*ratio);
n_y_pos = y_pos-_root._ymouse;
} else {
this._x = x_pos;
x_pos = x_pos-(n_x_pos*ratio);
n_x_pos = x_pos-o_x_pos;
this._y = y_pos;
y_pos = y_pos-(n_y_pos*ratio);
n_y_pos = y_pos-o_y_pos;
}
}
thanks
if any1 requires the FLA file to solve this i can get that 2 u too.
Actionscript To English Translation Required
hi,
can somebody translate this code into english for me?
!_root.file ? file = "filename.flv" : file = _root.file;
file is a variable but i'm not 100 % sure what '!_root' or '?' does? is it saying if _root.file hasnt been set yet, then set it to filename.flv?
thanks,
lukemack.
Actionscript Fpr Drag And Drop Game Required Help
hi
i am trying to do drag and drop in flash 5. i am creating a web game were if a symbol is dropped on a square it will triger a reaction behind the square. at the moment i have made each square a graphic symbol so it can be linked to another symbol etc.
all help appreciated
peter meehan
Actionscript Text Required From Flash Detection Kit
Help required,
I need help in getting the actionscript text from the flash detection kit file from macromedia. IN particular the flash_AS_detection.fla file in the actionscript folder of macromedia detection kit zip. Can someone please please please post the actionscript in the flash_AS_detection.fla file, as i have flash mx and can't open the file, it keeps saying unexpected file format. I really dont want to download a trial version because it could take me days as i'm on dial up
Or if theirs anyway you can resave the file as a mx compatibile file so i can open it.
Cheers
Arrays In ActionScript
I'm new, so please bear with me:
I want to create a clip that displays random characters in a text area until a specified time. At that time, the real text is displayed.
Example:
"a 7 & " --> "3 i 8" --> "c a t"
I want to use an array to store my characters, but so far I have no luck.
Below is some code that I feel will do the trick, but I don't know how to initialize (define/set) the array of characters I want to use.
Thanks.
e-mail: jp@dlowracing.org
for (i=0; i<numChars; i++) {
for (pauseTime=0; pauseTime<pauseAmount; pauseTime++) {
l[i] = Math.random()*94+32;
// pause or delay for 1/2 second.
}
}
Loops And Arrays Actionscript 3.0
hi, i know very little about action script 3 and what i am trying to do used to work with action script 2 but i guess now it's little different. please if some one has any idea....
var pic_array:Array = new Array("home", "photo1", "photo2", "photo3"......) // buttons
var pic_l = pic_array:length;
var myloader:Loader = new Loader();
for (var t = 0; t<pic_l ; t++) {
this[pic_array[t]].addEventListener(MouseEvent.click, Show_image);
}
function show_image(event:MouseEvent):void {
var request1:URLRequest = new URLRequest([pic_array[t]] + ".jpg")
myloader.load(request1)
addChild(myloader);
myloader.x=36;
myloader.y=145;
}
i have buttons with the same names as in the array. and everytime i click on one of the buttons than a bigger picture of this button is loaded to the screen. i know that the buttons works fine with the loop but i just cant get the name of the button that i click into the URL request.
var request1:URLRequest = new URLRequest([pic_array[t]] // trying to get the right name from the array // + ".jpg")
pleasee helllpppp....
Instance Actionscript Arrays
I am trying to find out how to use arrays in actionscript for setting certain objects to visible. I have 31 instances of movie object. I have set a counter and I want is the movie instance to become visible or not visible depending on the counter. If the movie instances are set as show1, show2, show3, etc... how could I use an array like
PHP Code:
counter = new Array();
// set all instances non visible
for (x=1; x<32; x++){
_root."show"+x._visible = 0;
}
// set instance = to counter visible
_root."show"+counter._visible = 1;
Is this possible in flash or is there a similar way that this can be done?
Thanks in advance
Text Input / Text Output...help With Actionscript Required..
hi
I have 2 text input boxes (input1 & input2) and 3 text output boxes ( output1 & output2& output3), also there are 2 buttons to add the text from the input boxes to the text output boxes.
What i need to do is this:
i input text into the 2 text input boxes and when i click the button for input 1 i want it to add the text from input1 to output1,i might then need to add input1 again and i want it to display in output2 as well as output1, then i might need to add input2 and i then want it to display in output3, then again i might want to add them in a totaly different order but always moving to a new output box if the above one is already full.
i hope you understand the gist of what im getting at and your help would be greatfully received.
thanx in advance
Actionscript -> Working With String Arrays
i have an array (say nData[20]) of 20 strings. i wish to print/compare the first character of each element.
using the following code doesn't help:
Code:
var i;
for(i=0;i<20;i++)
{ trace(nData[i][0]); }
this gives an 'undefined' output. so how do i go about it?
thanksssss...
Actionscript 2.0 Objects And Arrays Question
I'm attempting to create a small game to practice some new things I would like to learn. Right now, I'm attempting to load an XML file into Flash which creates an Item object and saves the object in with an array of objects. Loading the XML works fine, but for some reason, trying to push the new Items onto the array isn't working. I've tested several things, and as far as I can tell it just doesn't put anything in the array. I'm sure I'm overlooking something, but help would be appreciated. Here are the two classes I wrote to do this, as well as the code i'm using to test them. Thanks in advance for any help.
Code:
//GameInventory class - load XML file and is supposed to store the information in an array of Item objects
class GameInventory {
public var gameItems:Array;
private var i:Number;
public function GameInventory() {
var setName:String
var setHD:Number;
var setGD:Number;
var setID:Number;
var setHO:Number;
var setGO:Number;
var setIO:Number;
var itemslist_xml:XML = new XML();
itemslist_xml.ignoreWhite = true;
itemslist_xml.onLoad = function(success:Boolean) {
if (success) {
for (i=0;i<itemslist_xml.childNodes.length;i++) {
setName = itemslist_xml.childNodes[i].childNodes[0].firstChild.nodeValue;
setHD = Number(itemslist_xml.childNodes[i].childNodes[1].firstChild.nodeValue);
setGD = Number(itemslist_xml.childNodes[i].childNodes[2].firstChild.nodeValue);
setID = Number(itemslist_xml.childNodes[i].childNodes[3].firstChild.nodeValue);
setHO = Number(itemslist_xml.childNodes[i].childNodes[4].firstChild.nodeValue);
setGO = Number(itemslist_xml.childNodes[i].childNodes[5].firstChild.nodeValue);
setIO = Number(itemslist_xml.childNodes[i].childNodes[6].firstChild.nodeValue);
gameItems.push(new Item(setName,setHD,setGD,setID,setHO,setGO,setIO));
}
} else {
trace("Unable to load items list");
}
}
itemslist_xml.load("xml/itemslist.xml");
}
public function findItem(itemName:String):Item { //Does not work at all yet for some reason
for (i=0;i<gameItems.length;i++) {
if (itemName == gameItems[i].itemName) {
return gameItems[i];
}
}
}
}
//Item class - creates an object with the information it recieves from the GameInventory class when the XML file is loaded.
class Item {
private var itemName:String;
private var healthDefense:Number;
private var geekDefense:Number;
private var intellectDefense:Number;
private var healthOffense:Number;
private var geekOffense:Number;
private var intellectOffense:Number;
public function Item(getName,getHD,getGD,getID,getHO,getGO,getIO) {
itemName=getName;
healthDefense=getHD;
geekDefense=getGD;
intellectDefense=getID;
healthOffense=getHO;
geekOffense=getGO;
intellectOffense=getIO;
}
public function getItemName() {
return itemName;
}
}
//the test code that's one the first frame of the Flash movie
var listInventory:GameInventory = new GameInventory();
var item1:Item = new Item();
item1 = listInventory.findItem("Dictionary");
trace(item1.getItemName()); //displays "Undefined" instead of "Dictionary", like its supposed to.
Actionscript 2.0 Objects And Arrays Question
I'm attempting to create a small game to practice some new things I would like to learn. Right now, I'm attempting to load an XML file into Flash which creates an Item object and saves the object in with an array of objects. Loading the XML works fine, but for some reason, trying to push the new Items onto the array isn't working. I've tested several things, and as far as I can tell it just doesn't put anything in the array. I'm sure I'm overlooking something, but help would be appreciated. Here are the two classes I wrote to do this, as well as the code i'm using to test them. Thanks in advance for any help.
Code:
//GameInventory class - load XML file and is supposed to store the information in an array of Item objects
class GameInventory {
public var gameItems:Array;
private var i:Number;
public function GameInventory() {
var setName:String
var setHD:Number;
var setGD:Number;
var setID:Number;
var setHO:Number;
var setGO:Number;
var setIO:Number;
var itemslist_xml:XML = new XML();
itemslist_xml.ignoreWhite = true;
itemslist_xml.onLoad = function(success:Boolean) {
if (success) {
for (i=0;i<itemslist_xml.childNodes.length;i++) {
setName = itemslist_xml.childNodes[i].childNodes[0].firstChild.nodeValue;
setHD = Number(itemslist_xml.childNodes[i].childNodes[1].firstChild.nodeValue);
setGD = Number(itemslist_xml.childNodes[i].childNodes[2].firstChild.nodeValue);
setID = Number(itemslist_xml.childNodes[i].childNodes[3].firstChild.nodeValue);
setHO = Number(itemslist_xml.childNodes[i].childNodes[4].firstChild.nodeValue);
setGO = Number(itemslist_xml.childNodes[i].childNodes[5].firstChild.nodeValue);
setIO = Number(itemslist_xml.childNodes[i].childNodes[6].firstChild.nodeValue);
gameItems.push(new Item(setName,setHD,setGD,setID,setHO,setGO,setIO));
}
} else {
trace("Unable to load items list");
}
}
itemslist_xml.load("xml/itemslist.xml");
}
public function findItem(itemName:String):Item { //Does not work at all yet for some reason
for (i=0;i<gameItems.length;i++) {
if (itemName == gameItems[i].itemName) {
return gameItems[i];
}
}
}
}
//Item class - creates an object with the information it recieves from the GameInventory class when the XML file is loaded.
class Item {
private var itemName:String;
private var healthDefense:Number;
private var geekDefense:Number;
private var intellectDefense:Number;
private var healthOffense:Number;
private var geekOffense:Number;
private var intellectOffense:Number;
public function Item(getName,getHD,getGD,getID,getHO,getGO,getIO) {
itemName=getName;
healthDefense=getHD;
geekDefense=getGD;
intellectDefense=getID;
healthOffense=getHO;
geekOffense=getGO;
intellectOffense=getIO;
}
public function getItemName() {
return itemName;
}
}
//the test code that's one the first frame of the Flash movie
var listInventory:GameInventory = new GameInventory();
var item1:Item = new Item();
item1 = listInventory.findItem("Dictionary");
trace(item1.getItemName()); //displays "Undefined" instead of "Dictionary", like its supposed to.
[ActionScript 2.0] Dynamic MovieClips And Arrays
actionscript Code:
//Enemy Arrayvar enemyArray = new Array();//Enemy functionnewEnemy = function () { var enemy = _root.attachMovie("angryEyes", "zombie"+i, _root.getNextHighestDepth()); addEnemy = enemyArray.push(enemy); // this is the part that adds to array i++; enemy._y = random(500); enemy._x = 800; enemy.onEnterFrame = function() { this._x -= random(10); this._y += -2.5+random(5); if (wall.wall1.hitTest(this)) { removeMovieClip(this); } }; trace(enemyArray.pop());};//Spawn new Enemy at an interval of 800mssetInterval(newEnemy, 1000);
My trace returns
_level0.zombie[type Function]
_level0.zombieNaN
_level0.zombieNaN
_level0.zombieNaN
_level0.zombieNaN
So maybe .push() should have something else specified inside the brackets? What are your thoughts?
Rotation With Arrays Actionscript Modify Help
When i was searching internet i found this code just fitting what i want but it was made for flash player 6 and if i save it in a higher publish setting it's arrays go wild.I need to modify the code for flash 9 cs3.
Any help will be appreciated.
Code:
fscommand("allowscale", "false");
links = new Array();
links[1] = ["http://www.flashstar.de","Flashstar"];
links[2] = ["http://www.flashangel.de","Flashangel"];
links[3] = ["http://www.flashpower.de","Flashpower"];
links[4] = ["http://www.multimedia.de","Multimedia"];
links[5] = ["http://www.flashforum.de","Flashforum"];
links[6] = ["http://www.flashmx.de","FlashMX"];
posX = Stage.width / 2;
posY = Stage.height / 2;
// Clips Erzeugen
anzahl = links.length-1;
for (var i = 1; i < anzahl + 1; i++) {
attachMovie("clip", "clip" + i, i);
}
// Global Signal
_global.signal=true;
this.onEnterFrame = function() {
if (signal) {
mausPos += ((_root._xmouse - posX) / 100);
for (var i = 1; i < anzahl + 1; i++) {
winkel = ((mausPos + (360 / anzahl * i)) * Math.PI) / 180;
this["clip" + i]._x = posX + (Math.sin(winkel) * 300);
this["clip" + i]._y = posY + (Math.cos(winkel) * 50);
this["clip" + i]._xscale = 100 + (Math.cos(winkel) * 50)
this["clip" + i]._yscale = 100 + (Math.cos(winkel) * 50);
this["clip" + i].swapDepths(1000 + (Math.cos(winkel) * 100));
this["clip" + i].txtName = links[i][1].toUpperCase();
this["clip" + i].url = links[i][0];
this["clip" + i].onRelease = function() {
getURL(this.url, "_target");
signal = false;
};
this["clip" + i].onRollOver = function() {
signal = false;
};
this["clip" + i].onRollOut = function() {
signal = true;
};
}
}
};
// (Logo)
planet.swapDepths(999 + 1);
Thanks.My last hope..
Actionscript, Arrays, Recording Symbol Movement Within The Swf
my goal is to make a record button, a stop button, and a play button.
when you hit the record button it starts recording the movements of the movieclip by storing the coordinates in an array.
I've done all of that (download the .fla here: http://filehaven.sfdt.com/viewtopic....703&highlight=)
now I need some help figuring out how to play the coordinates that I stored in the array.
feel free to mess around with the .fla and THANKS.
Data Encapsulation FLAW On Arrays In Actionscript 2.0?
I have been programming in Actionscript 2.0 using the class constructs and I have run into something which is kind of curious which I would like to share with you all. It would seem that Actionscript 2.0 has a flaw in handling data encapsulation in dealing with Arrays.
Try this: create a class, say Car, and define it this manner:
ActionScript Code:
class Vehicle {
private var numberOfWheels:Number;
private var vehicleName:String;
private var occupants:Array = new Array();
public function Car (vName:String, nWheels:Number) {
vehicleName=vName;
numberOfWheels=nWheels;
}
public function addOccupant (occ:Occupant):Void {
occupants.push(occ);
}
public function numberOfOccupants():Number {
return occupants.length;
}
public function listOccupants():Void {
for (var i:Number=0; i<occupants.length;i++) {
trace(occupants[i].getName());
}
}
}
Now create the class to hold the occupants as follows:
ActionScript Code:
class Occupant {
private var nameOfOccupant:String;
private var ageOfOccupant:Number;
private var isDriver:Boolean;
public function Occupant (oName:String, oAge:Number, oIsDriver:Boolean) {
nameOfOccupant=oName;
ageOfOccupant=oAge;
isDriver=oIsDriver;
}
public function getName():String {
return nameOfOccupant;
}
}
Finally, create this code at the movie root:
ActionScript Code:
// create a new vehicle and fill it with 3 occupants
var car:Vehicle= new Vehicle("Jeep", 3)
// now fill it up with 3 passengers
var occ:Occupant =new Occupant ("Marco", 46, true);
car.addOccupant(occ);
occ=new Occupant ("Mary", 42, false);
car.addOccupant(occ);
occ=new Occupant ("John", 12, false);
car.addOccupant(occ);
// now the car has three passengers
// you can confirm it here:
trace(car.numberOfOccupants());
// now let's create a completely different vehicle:
var bike:Vehicle= new Vehicle("bicicle", 1)
// and let's add the passsenger for the bike
occ=new Occupant ("Tom", 16, true);
bike.addOccupant(occ);
// NOW watch this:
trace(car.numberOfOccupants());
// returns 4 and not 3!
trace(bike.numberOfOccupants());
// returns 4 and not 1!
// both arrays, instatiated as private variables in separate instances, point to the same data!
bike.listOccupants()
// you get:
//Marco
//Mary
//John
//Tom
It seems as though Actionscript is not properly encapsulating the arrays. All the other private data items (names, number of wheels, and so on) are being dealt with correctly but arrays are not.
As I am not an expert on Actionscript I may be misunderstanding the nature of the Array type but I would expect it to have created two completely independent arrays and not be addressing the same one!
Am I doing something wrong? What do you think?
BTW: I have tried this with Flash MX 2004 Professional and with Flash 8 with the same results.
Actionscript Compare Two Arrays And Create New Array
I have two arrays which contain something like:
array_one = (a->b, b->c, c)
array_two = (a, b, b->c, c)
and I want to concatenate these (I can do that) but remove duplicates. So at the moment I have:
array_three = (a->b, b->c, c, a, b, b->c, c)
whereas I want it to be:
array_three = (a->b, b->c, c, a, b) the order doesn't matter.
Can someone show me how to do this please? I think I either need to compare each element before concatenation, or somehow remove duplicates afterwards?
Using Arrays In A ASCII (text) File Being Included By ActionScript
Ok, first of all I'd like to introduce myself really quick. I've been looking around and think this is a great site for some time now, finally registered because I had a question that has stumped me. I just started learning ActionScript a couple days ago and have made some great progress (it's easy for me to pick up as I've been doing PHP for some time now and the syntax is quite similar in some parts.)
Now, on to my question:
I'm loading variables from an ASCII file in the same directory (on a computer, this is an .exe application.) Now the file loads fine, but what I'm trying to do is use arrays in the text file. Here's the context of my text file:
Code:
&servers=1
&server[1]=http://www.agigagames.com/YaPP/
&servername[1]=Testing server
&loading=NO
My code for loading the file:
Code:
loading = "YES";
loadVariablesNum("servers.yafc", 0);
The problem is in the next bit of code, I can't get it to add the item to the listbox. It adds an item, but all that's there is a , yet I've tried putting in a dynamic text box with the var of servername[1] and it displayed fine.
Code:
n = 1;
while (n <= servers) {
serverslist.addItem(servername[n],server[n]);
n++
}
stop();
I appreciate any responses, thanks!
Arrays In A Text File To Arrays In Flash
What i am wanting to do is get an array list from an external file and put it into flash arrays, the code i tryed to use was this:
PHP Code:
for (i=1; i<33; i++) {
if(id=="undefined" || id=="NaN"){
} else {
id[i] = id(i)
}
}
But that dosent work obviously.
I know ive got the
PHP Code:
id[i]
bit right, but i dont know how to do the bit from the text file.
in the file it goes like this:
PHP Code:
id1=432&id2=324 ect
So basically what i am trying to ask is how to in a look do variables using the i (id plus the i at the end). Anyone got any ideas?
Calculator
One thing that I would really like to do is make a calculator that one can put in numbers and then hit the button to get an answer. A good example is a mortgage calcultor. But I fail to understand were to put the actuall equations and to declare the variable and would I use a textfield for what, etc. Doing the graphics is no big deal.
Does anyone know how to explain this?
Calculator
yeah i'm doing a calculator just for the hell of it. any i'm stuck i have no idea how to do it lol
this is what i have so far:
scene 1, frame1:
4 buttons called 7,8,+ and =, instance names seven,eight,plus and equal. i have a input txt also...Var display
on same frame i have the code:
Code:
display = "";
memory = 0;
seven.onRelease = function () {
if (memory == 0) {
display += 7;
}else if (memory != 0) {
display = ""; //resents display to nothing
display += 7; //gets a different 7even
}
}
eight.onRelease = function () {
if (memory == 0) {
display += 8;
}else if (memory != 0) {
display = ""; //resents display to nothing
display += 8; //gets a different 7even
}
}
plus.onRelease = function () {
memory += display; //memory gets whatever value display has
if (memory != 0){
display = memory;
}
}
now as the code i know it sucks but i'm posting it so u guys can give me some ideas how to do it.
THANK YOU...
edit here is the file also
http://www.geocities.com/hydrasweb/Untitled-1.fla copy paste link in ur browser /edit
Calculator?
does anyone here know of any tutorials on building a calculator in Flash MX?
Help With Calculator
R.O.I not working
in my fla the
net benefit to your company = (in how many sales outlets... * wht is duration.....* cost of campaign per day)-profit made on incremental sales
but the answer it gives i.e net benefit to your company is not correct, it doesnt change with the change in the number of sales outlets or change in the duration of campaign
i think the problem is with the decimal figure in the cost of campaign per day, u can test by only clicking the no of outlets and duration of campaign buttons randomly, see it shows 5000
please check my fla and reply, i have flash mx
Calculator
could any one show me how to make a calculator?
Need A Calculator In AS3 Please...
I've been asked to make a calculator in as3 in a day! but i only have the basic understanding skills of as2.
Can anyone help in anyway?
[CS3] Calculator
Hello, I was wondering if someone could point me in the right direction on how to create a reverse mortgage calculator for a real estate web site?
Thanks
Calculator Help
I'm making a calculator in Flash CS3 using actionscript 3.0.
It has the Multiply, Divide, Plus & Minus buttons.
When i input the code for one button, that button works, but when i input the code for more than one, none of the buttons work.
What am I doing wrong?
Download Calculate.fla
Code:
MinusButton_btn.addEventListener(MouseEvent.CLICK, doMyCalculation);
function doMyCalculation(e:MouseEvent):void
{
var total : Number;
// PROCESS
total = Number(N1.text)-Number(N2.text);
// OUTPUT
total.text = String(myAnswer);
};
MultiplyButton_btn.addEventListener(MouseEvent.CLICK, doMyCalculation);
{
var total : Number;
// PROCESS
total = Number(N1.text)*Number(N2.text);
// OUTPUT
total.text = String(myAnswer);
};
DivideButton_btn.addEventListener(MouseEvent.CLICK, doMyCalculation);
{
var total : Number;
// PROCESS
total = Number(N1.text)/Number(N2.text);
// OUTPUT
total.text = String(myAnswer);
};
PlusButton_btn.addEventListener(MouseEvent.CLICK, doMyCalculation);
{
var total : Number;
// PROCESS
total = Number(N1.text)+Number(N2.text);
// OUTPUT
total.text = String(myAnswer);
}
Thanks guys
Calculator
I am looking for a good example of a calculator developed with Flash. Know where I can find one?
Calculator
Hi,
Alright.. iv made a calculator.. maybe not the greatest accomplishemnt of man kind.. but i like it .. bbut i have some problems.. with the way i ahve it set up i can onyl punch in singel digits... i basicly have different frames for the differnt functions in the calcualtor... i have 3 text fields.. one is for the first number that is punched in, the second on is for the second number that is punched in, and the last one is the result of the calcualtion. they have variable names, math1, math2, and math. The script in the equals button performs the calculation. the script looks like this:
math = math1+math2;
eveything in the calculator is very basic AS..
The buttons have very basic script to... for example.. the number 3 had:
on (release) {
math2 = 3;
}
and after u click the type of calcualtion u want to do, the number 3 would have a script like this:
on (release) {
math2 = 3;
}
i cant imput double didgits, only singel digits.. how do i change this to accept all digits?
Help For This Calculator
Hi Users,
I am making a survery form kind of things and is using the Flash MX UI components for the first time. I have seen an example on the web at : http://www.plan-itgranite.com/calculators.html. Now as I am new to actionscript I am facing some problems. I have attached my .fla file please check it out and if possible tell me the code for:
1) If the user checks more than one check box in the first page, how can I store all the values and show them in the end.
2) Similarly as there are 3 pages in my .fla, I have seen that the value stored from Page1 doesn't show in the end.
Please help me in this matter as it is a part of my upcoming project. One more thing is please refer me a book for Actionscripting which should be for a user who doesn't know about actionscripting and covers all the UI components of the Actionscript. Should be for a basic programmer.
regards,
Xeeschan
Calculator In MX
Looking to do a simple calculator in MX. Looked through tutorials but may have missed a lesson. Any recommendations?
Calculator
PHP Code:
half_btn.onRelease = function() {
output1 = input1/2;
};
i have that applied to a button.. but instead of dividing the input data in half.. it subtracts 2.. any ideas why?
Calculator
is it hard to make this? Calculator link
I just need 4 fields. thanks
|