ActionScript 2.0 :: Use Multiple "if" Statements?
Mar 1, 2002say i want something to happen, but I only want it to happen if more than two conditions are satisfied...is there a way to use multiple "if" statements?
View 3 Repliessay i want something to happen, but I only want it to happen if more than two conditions are satisfied...is there a way to use multiple "if" statements?
View 3 RepliesSo I am creating a drag and drop game but the thing is that there is not one question for each statement. Is it possible to have say... 10 statments on the right and one "box" on the left where the statements can be dragged to, if its correct it stays there, if its incorrect it goes back to its original position.
View 12 RepliesI need to put a load of MC's on stage with the use of an array as such:
Code:
for (var i = 1; i = 4; i++) {
if (reg[i] == "singlewall") {
var Wall:MovieClip = new wallClass() as MovieClip;
mainClip.addChild(Wall);
}
}
I need a lot more then 4 though and I need a way to make new "Wall" variables
Tried doing it with:
Code:
for (var i = 1; i = 4; i++) {
if (reg[i] == "singlewall") {
var Wall:MovieClip = new wallClass() as MovieClip;
Wall.name = "mc"+i;
mainClip.addChild(Wall);
}
}
This does not work though, yields an infinite loop somehow
I'm building a quick products display app for my company (basically customers put in certain numeric values and the app recommends a product based on the numbers.) I've done this with if statments and addChild()s
Now if they've gotten one result and they want to try with different values I need to removeChild() the product images from the stage.
So far I have this working by adding the addChild()s to an Array and using a for loop to remove them everytime the calculate button is hit. This works fine until I get to product double ups (some products can work across multiple values) then it errors.
Below is part of the code I've shorthanded some of the parts which are working fine as well as the repeat parts so that it's not just a whole blob of code
Code:
stop();
import flash.display.MovieClip;
equal_btn.addEventListener(MouseEvent.CLICK, equClick);
[Code]....
I've been developing an AS3 based 2D fighting game engine (like Street Fighter II), and have run into an issue. I'm using if/else statements in my onEnterFrame function to hit test my fighters. This works great in my first if/else statement, but for some reason it doesn't recognize my second if/else statement that follows the first. I know it's not the code, because if I bring the second if/else statement up and place it above the first statement (simply swapping the order), the hit test is successful. Why is it that only the if/else statement that comes first works, but any that come after it don't?
Here's my code:
function onEnterFrame(event:Event):void {
//MOVE THE char1
PlayerBase.players[0].x += plyr1vx;
PlayerBase.players[1].x += plyr2vx;
[Code] .....
I've also attached a .zip file with my published files so you can see the issue in the game (must be viewed in a browser for keys to work correctly). Move the left player using "A" and "D" keys. Make him punch with "Z" and kick with "X". Punch is the first if statement in my code, and kick is the second if statement (not working).
I'm trying to do a binary search in a for loop. However, flash does not like the following for loop.
for(var select:int = Math.floor((min + max / 2)), var turns:int = 0;
turns < input.length / 2 + 1;
turns++, select= Math.floor((min + max / 2))){
if(input[select] > want){ max = select;
} else if (input[select] < want){
min = select;
} else {
return select;
}}
On the first line I get 1084: Syntax error: expecting identifier before var. I think I know why (I'm using , to separate the different statements), but how do I fix it? ; won't work since it's what the for loop uses.
( var select:int = Math.floor((min + max / 2)) ;
var turns:int = 0);
turns < input.length / 2 + 1; //etc
does not work either.
I am working on a puzzle has four different eyes, nose, and mouth. These can be placed on a blank head. I want to be able to place all of the same parts of the face, and have a response that says "Beauty" if the mix up the pieces from different faces, it will say "Beast." I don't know how to set up the AS3 to make this work.
View 1 RepliesI am trying to check 3 scores at once. Is there a better way to code this... I want to check to see if they are all tied? If one score is greater than another? Seems like there should be a more cleaner way.
[Code]....
I have a series of images loaded in via XML and assigned to "loady" movieclips. This code works fine:
Code:
_root.myMCL.loadClip(_root.myImages[0].attributes.url,_root.loady0);
_root.myMCL.loadClip(_root.myImages[1].attributes.url,_root.loady1);
_root.myMCL.loadClip(_root.myImages[2].attributes.url,_root.loady2);
_root.myMCL.loadClip(_root.myImages[3].attributes.url,_root.loady3);
[code]...
I want to replace this with a loop since I know the total amount of items (myImagesNo), but this isn't working:
Code:
for (i=0; i<_root.myImagesNo; i++) {
_root.myMCL.loadClip(_root.myImages[i].attributes.url,this["_root.loady" + i]);
}
I have a series of images loaded in via XML and assigned to "loady" movieclips. This code works fine:[code]
View 1 RepliesBelow is code that has a timer countdown that reads off of the computer. Below in bold is code to read "if it reaches the date, go to and play frame (2).
[Code]...
Below is code that is manual input - I had set up a dynamic txt field in flash named it : raffle_tix_remain When loaded on to the host I can manulally update the xml code and the change will take effect. raffle_tix_remain.text = root.loaderInfo.parameters.raffle_tix_remain;
My question: Since the raffle_tix_remain is a manual input from a user to xml Is there a way to tell flash once it refreshes and "raffle_ tix_ remain" goes to (0)zero gotoAndPlay(2); and let it play like a "sold out" sign i guess that would be a if else statement.
[Code]...
If they get a question wrong in my quiz ( weakest link) the money clip goes to zero and it goes onto the next question. If they get it right the money clip advances and they go onto the next question. I want to include each time that it should only go onto the next question if all questions have been asked. SO i want an extra if clause in both sections, saying if current question is more than 11 go to '#game over"The questions are saved in the frame of the quiz
_root.qArray = new Array("question: A;B;C;D")
_root.qArray.push("Question?:A;B; C; D")
There are 11 questions.At the moment at the section with choosing answers I have
function selectAnswer(n) {
// correct
if (answers[n] == correctAnswer) {
_root.money.nextFrame();
[code].....
I am trying to use if and else statements and failing. I am either completely missing their purpose, or just not writing the correct code. Scenario: I have designed a gallery that consists of animation in movie clips that are placed on the time line. With the if/else statements I need Flash to know what movie clip the user is on, so that the users next action loads the correct movie clip.
[Code]...
Is it possible to double up If Else statements? [code]...
View 2 Replieshow do i create an if statement for some buttons to say something like:
-if button1 is pressed go to frame1
-if button2 is pressed go to frame2 etc.
i know i could use button1.onRelease = function(){blah blah;} but i would like to start using if statements and this is a good place to start i guess
I want to join two if statements together and I'm unsure of the syntax. This is what I have but it is obviously wrong. if (Key.isDown(Key.RIGHT) or if (moveRight_btn.onPress){
View 7 RepliesHow to do a rollover button where you rollout and it doesn't another option depending on the current frame. So I decided to open up another actionscript file and do a test so that I knew that I could make an if statement work in a barebone state. And I can't get it to work
First I stated my variable to be 0. I added 3 buttons. Button One makes the variable unit "myVar" to 1 and Button Two makes it 2. And my output button reacts to these variable changes. But it doesn't work.
ActionScript Code:
One_btn.addEventListener(MouseEvent.CLICK, OneV);
Two_btn.addEventListener(MouseEvent.CLICK, TwoV);
Output_btn.addEventListener(MouseEvent.CLICK, OutputV);
var myVar:Number = 0;
function OneV (event:MouseEvent):void {
[Code] .....
well after I made all of the conditional statements I came to the conclussion and the annoyance that I cannot retrieve the statements value, I need help:[code]it does not return the value.. why?
View 5 RepliesI was wondering if anyone would be able to shorten this.All of my attemts at it have resulted in errors/not working.
ActionScript Code:
enemy1.onEnterFrame = function() {
if (this.hitTest(p1)) {
[code].....
After searching for how to do this i discovered the Get/Set functions of as.3. The only problem is that i am not experienced enough with this kind of statement to get it working, so i have come here to seek from the wise and masterful members Here is some more info:Inside a fla called "Main" i have 2 MovieClips. The first is called Main and has a class linking to the com/Main.as file which has this code:
Code:
package com{
import flash.display.MovieClip
[code]....
used to be able to handle variables and if else statements back in AS2.0, but I don't know how to go around them in AS3.0For instance, a code like this:
stop();
var pageNum = 1;
var pageAnim = 1;
[code]....
i have got a project im working on that requires if statements
basically im wanting to create 2 or more statements detailling if an answer is right, to move onto the next question but before it does that, to play an audio clip then move on. the next statement will be similar, but i cannot remember how to create them i.e. the syntax.
if i could get a response ASAP that would be gr8, as i have 2 weeks to get it done.
I'm making a small movie in Actionscript 2, but have found a problem related to the scope of my functions.Figure I have an audio/mute movieclip, with a global variable called "elaudio" (boolean). When "elaudio" == true , the volume is up, when "elaudio" == false, the volume is muted.I'm attaching sounds from the timeline using Actionscript with an object sound, this way:
Code:
_root.audio.attachSound("myWav");
_root.audio.start();
[code].....
I'm trying to make a "next track" button. "T" is meant to be track number, and every time they click this button, I wanted "T" to increase by one until T>4 where I need it to go back to T=1 (I've only got 4 tracks). Then, I want, depending on what "T" equals, for it to start playing Track"T" and stop playing previous track. I also want the track playing to be looping continuously. At the moment, everything is muted, until I press the button; where it then plays all four tracks at once. I also have a problem with the mute button, but I've got a strong feeling both are of the same reason. I think my problem is that it does not know what "T" equals to begin with so it accepts all if statements; playing all tracks. But I'm new to Flash (my second project) so I'm not sure.
on (release){
stopAllSounds();
T =T+1
if (T>4){
T=1
} if (T = 1){
_root.snd1.start(0, 100);
[Code] .....
How do you script a Pause of X Seconds on X Frame and also on that frame have a button release statement that can take you forwards or take you backwards, elsewhere in the timeline - Without affecting the 'Pause' statement... therefore not mucking up the timeline and causing it to jump around at the end when all catches up?I take it once a pause has taken place - a button that can take you elsewhere, if clicked on - does not Cancel the initial pause and therefore lies my problem?
View 3 RepliesWhen use the full path name and the identifier of a movie clip, my conditional statement works fine. However, when I swap the identifier out with "this", it no longer works. This script is contained within the movie clip I am trying to reference. I have found that, "this" works fine by itself on the timeline. It just stops working when I place it within a conditional statement.
Here is my script:
function functionOne() {
randomX = 550*Math.random();
randomY = 400*Math.random();
} functionOneInterval = setInterval(functionOne, 1000);
function functionTwo() {
[Code] .....
The reason I am trying to use "this" instead of the identifier name is because the movie clip it is referencing will be duplicated. This script here generates a random destination point for an enemy spaceship and tells it to constantly move to the changing points. This script is contained within the enemy spaceship movieclip, and I am planning on duplicating several of them at once.
In this example, is there anyway to fade in and out 'mcContactAmer' and 'mcY' as well as place them at specific coordinates, other than externally load them as swfs? This is the only thing holding me back from moving forward on this project and my boss would like to move forward,
View 3 RepliesThis time I am trying to use button functions with in IF statements. However I am having trouble with the if statements regonizing the currentFrame(); or currentFrameLabel();. I want diffrent button functions depending on what frame the playhead is in. But the frames are in diffrent movieclips and what not.The next problem is that I do not full understand the way to do frame paths (IE Root.Movieclip.Movieclip) in AS3. series of tutorials that I could read and follow,
View 12 RepliesI'm working with 2 global variables and I need to compare them on 6 different button function clicks for a lot of different scenarios.[code]My function is starting to look like this;[code]only problem i see is that there are many different scenarios and this if statement could get very long. Is there a way to combine it somehow so there wouldn't be that many else if's?
View 3 RepliesI want to write AS3 code that has 2 variables; one that acts on odd numbers and the other that acts on even numbers entered into a text field ?(sorry I'm not making much sense here! Will explain the context further)I'd like to use an XML calendar in my Flash project that shows the odd or even dates in the calendar depending on what number you enter in a field being either an odd or even number. (This is based on ACT Water Restrictions odd and even watering restrictions)It means that if your street number is an odd number you can use water as per restrictions when the date also is an odd number. Similarly, if your street number is an even number you can water as per restrictions when the date also is an even number. You're probably familiar with this system.
The context is for my Adult Migrant students to understand the concept of our water restrictions here which is governed by this odd and even system.So what I'm doing to do next is buy a cheap XML calendar online which I can adapt for my project but I'm not sure whether I should be approching this code problem with an if/else statement to get the results or something else?how to write the code!!
if my number I enter is an even number then display (in an XML calendar) even days
else
if my number I enter is odd then display (tin an XML calendar) odd days