ActionScript 3.0 :: If Statement And Random Movieclip?

Aug 3, 2010

I'm creating a small guessing game where on stage there are 6 squares, and the user has to click on a square, and see if it's the correct one (it should be a bit more exciting when it's finished!) The random answer is created using the math.random method and I'm using an array for the square movieclips. The problem I now have is with the IF/ELSE statements.

have a look at the following code, and the bit I need you boffins to look at is just after the if statement.

var myArray:Array = [mc_square01, mc_square02, mc_square03, mc_square04, mc_square05, mc_square06];
myArray[Math.floor(Math.random() * myArray.length)].addEventListener(MouseEvent.MOUSE_DOWN , chooseMe);

[Code].....

View 3 Replies


Similar Posts:


Flash :: "IF" Statement, Within A For Statement, To Control Movieclip Within Movieclip?

Dec 18, 2011

I have a movieclip on the screen called "mc_bg". Within this movieclip are 7 movieclips called "barrier1" through "barrier7".From main.as I want to be able to do this call:

for (var i: int = 1; i < 3; i++ ){
trace("got here")
trace(mc_bg["mc_barrier" + String(i)])

[code]....

View 1 Replies

ActionScript 2.0 :: Random Animation - Use The ContinueTo() Method, That If() Statement Isnt Being Called?

May 24, 2007

I'm working on a animation for a charity and i need to make some birds fly around the stage randomly, and change _xscale depending which direction they are moving.I have an if() statement to check if the new destination point is smaller or bigger than the current _x position of each bird. This works perfectly, but when i use the continueTo() method, that if() statement isnt being called.here is the code for the birds.

function flight(){
for (var i=0; i<birds; i++){
var bird:MovieClip = attachMovie("crane","crane"+i,i+1);[code]....

View 6 Replies

ActionScript 2.0 :: If Statement From Within Movieclip

Feb 8, 2009

I am using Flash CS3 AS2. On my main timeline I have 3 buttons, each of which, when pressed go to the same frame in which a movieclip loads. However, when the movieclip gets to the end I want it to gotoAndPlay a different frame on the main timeline depending on which button had been pressed.

I'm guessing I need to use button instance names in combination with an if statement from within the movieclip but I'm not sure exactly.

So far I have tried

if (isPressed= "btn_latest_mar_cgn"){
_parent.gotoAndPlay("latest_cgn");
}

but something isn't quite right about that. Do I need to put something on my main timeline

View 7 Replies

ActionScript 3.0 :: Movieclip In Conditional Statement Of If?

Nov 28, 2009

In the code below how can I use the movieclip in the conditional statement? This is simplified, there is lots more going on but the basic issue is shown. I want to say if currently dragged mc is dot1_mc do the copyDragTo35 function

PHP Code: var item:MovieClip;
//add event listeners to all dots
kite_mc.dot1_mc.addEventListener(MouseEvent.MOUSE_DOWN, onItemDragStart);
kite_mc.dot2_mc.addEventListener(MouseEvent.MOUSE_DOWN, onItemDragStart);
function onItemDragStart( e:MouseEvent ):void {

[Code]...

View 2 Replies

ActionScript 2.0 :: If Then Else Statement Load Movieclip?

Jan 29, 2011

I have built a calculator with a running total variable (stotal) this is working great. There are 30 buttons each having its own value each add or subtract from "stotal".The attached is a much scaled down and simplified version of the calculator. In this sample each button has a value of 200. If the user gets to 1000 or more I want to load an exiernal SWF "succes.swf" that notifies them they have reached 1000.

Here is the AS for one of the buttons. I know I need to wtite this as an "If then Else If" statement in order to get it to work but I am not having much luck;

q1a.onRelease = function(){
if (a1a==true){
a1a=false;
_root.stotal -=200;

[code]....

View 6 Replies

Flash :: Accessing Movieclips Within Movieclip Using For Statement?

Nov 1, 2011

I am trying to access movieclips within my movieclip using a for statement. To try and make this clear, here is how it looks at the moment:

sections = Holder movieclip where dtf_sections is placed, as well as other clips that are needed.

dtf_sections = Where all the title movieclips are placed that are going to be used when called. Placed in here to make it easier to move, within sections

title = Movieclip that contains the text that needs to be changed, within dtf_sections

Here is my code that works:

sections.dtf_sections.title1.dtf_title.text = "Section 1"

There are upto 10 titles within dtf_sections. So, what I thought would work is this:

for(var i:uint=1; i<10; i++){
sections.dtf_sections.["title"+String(i)].dtf_title.text = "Section" +(i)
}

The reason why they are within the movieclips is masking, and appearing at different times.

View 1 Replies

ActionScript 3.0 :: Movieclip Focus Not Working On If Statement

Jul 7, 2010

I have created menu which has roll over and out animations.What I am trying to achieve is to play the roll over animation when rolling over the menu, but stop the roll out animation IF the focus has been set on a specific movieclip.[cod]I am not sure what I am doing wrong, but if I trace the stage focus inside the if statement nothing happens, but it works if I trace it on else statement(gives null) which means that the if statement is bypassed and the else is played.

View 7 Replies

ActionScript 3.0 :: Movieclip Focus Not Working On If Statement?

Jul 6, 2010

I have created menu which has roll over and out animations. What I am trying to achieve is to play the roll over animation when rolling over the menu, but stop the roll out animation IF the focus has been set on a specific movieclip.

Here's my code:

Code:
function menuOut(e:MouseEvent):void
{
stage.focus == contentMc;

[Code]....

if I trace the stage focus inside the if statement nothing happens, but it works if I trace it on else statement(gives null) which means that the if statement is bypassed and the else is played.

View 1 Replies

ActionScript 3.0 :: Created Some Movieclip Buttons / Set A Statement To Disable It

Nov 18, 2009

I created some movieclip buttons, set a statement to disable it, but I can't enable them again when another button is selected how can i resolve this?[code]

View 4 Replies

ActionScript 2.0 :: Continue Statement - New SWF Is Not Loaded Into Movieclip After Reaching The End

Dec 18, 2005

[Code]...

What I'm trying to do is: When this button is pressed, whatever is in the current news_Clip movieclip goes to frame 71 and plays till it reaches the end of the outro animation which is frame 101. When it reaches frame 101, I want to load a new swf into news_Clip. Using the above code, the contents of news_Clip does its outro animation but the new SWF is not loaded into it after reaching the end. I've been screwing around with this for the past 7 hours and can't figure out what I'm not doing or doing wrong.

View 1 Replies

ActionScript 2.0 :: IF Statement - MovieClip Drag And Drop Into Certain Area

Mar 27, 2008

I am wondering if I can write an IF statement that is a movieclip is drag and drop into a certain area that an event occurs. Everything I try seems not to work any idea?

View 2 Replies

ActionScript 3.0 :: If Statement : Trigger If The Function Is Triggered By A Specific Movieclip?

Jan 10, 2010

I have a bunch of event listeners that refer to different movieclips but trigger the same function.I have an if statement within this function that I need to trigger if the function is triggered by a specific movieclip.

ActionScript Code:
//movieclip stuff....
addChild(backgroundPoint);
backgroundPoint.addEventListener(Event.ENTER_FRAME, animateBall);

[code]....

I know I could just create two separate functions but the code within the function (not shown here) is fairly long and I dont like repeating code.

View 2 Replies

ActionScript 2.0 :: First Requirement Of The If Statement When Type In The Proper Input And Go Straight To The Else Statement

May 14, 2009

Having a few problems with what I thought was a simple if statement. Here is the code:

[Code]...

I can't quite figure out the small problem with the code. It seems to just bypass the first requirement of the if statement when I do type in the proper input and go straight to the else statement.

View 7 Replies

ActionScript 2.0 :: Random MovieClip Load In Another MovieClip, With Its Own Functions?

Dec 29, 2002

I've got 12 MovieClips, which all have specific functions in the movie. Those MC's will appear and dissappear after a few seconds. But what I want is, that those MC's have to appear at random .If all 12 MC's have appeared, the appearance has to be stopped. So for example MovieClip number 4 has to appear just once. So 12 MC's will appear, but everytime when the movie starts, the appearance has an other sequence.What is written above I want to place in an other MC. So there is one MC which 'load' 12 MC's within it

View 2 Replies

ActionScript 1/2 :: Execute Code In Previous If Statement If Second If Statement Is Executed?

Aug 31, 2011

if (variable == 1){
//code
//Execute this code.
} else if (variable == 2) {
//code

[Code]...
 
I dont want to copy the code from the first into the second and the first and second into the third.
 
My mind isn't working and there is probably an extremelly simple way to get this working.
 
I know I could used functions but for some reason it stops the instance referencing working: _root["bullet"+j] doesnt work in a function.

View 7 Replies

ActionScript 2.0 :: Loading Data From XMl File And Uses It To Run An If Statement. If Statement Fails?

Oct 10, 2008

The Flash movie contains 2 Text files, one Component button, and 1 component checkbox.The purpose of the application is to load an XML file(works)Populate 2 text fields with information from the XML file(works)Compare the two text fields, if they contain the same information then the checkbox, via AS is told to be selected. (Heres the problem);

Heres the code:

Code:
runCode_btn.onPress = function() {
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = function(success) {

[code]....

The idea behind this app is that its an electronic form. The user fills it out, the information is then sent to a newly created XML file, months later the open the XML file in flash, and Flash fills out text fields and check and or unchecks Checkboxes based on the XML data.CheckBoxes are mandatory.But I don't see how I'll be able to use them if i can't create and condition statements based on the loaded Data.

View 1 Replies

ActionScript 2.0 :: Create If Statement That Would Load Movie Clip After Different Movieclip Is Loaded

Apr 19, 2004

is there a way to create an if statement that would load a movie clip after a different movieclip is loaded.i have text_mc and scroll_mc. I dont want scroll_mc to load unless the content is loaded into the text_mc.I tryed to make an if statement sort of like a something used for a preloader but I must have been off just a bit because it was not working. I dont even know if it possible.

View 7 Replies

ActionScript 2.0 :: If Statement Inside If Statement Won't Work

Mar 30, 2011

why this code won't work

[Code]...

I'm sure you can put if statements inside other if statements, seriously I can't figure it out

View 4 Replies

ActionScript 2.0 :: If Statement - Goto A Random Frame Which Will Play A Movie When The Button "one" Or The Button "two" Is Pressed

Jul 20, 2006

its a gambling game of chance and I want it to go to a random frame which will play a movie when the button "one" or the button "two" is pressed. so on each button, I have the code:

[Code]....

View 7 Replies

ActionScript 3.0 :: Another 'if' Statement Inside An 'if' Statement?

Sep 22, 2010

I need to write an if statement inside an if-else statement. But no matter how I write it it keeps giving me a syntax error.The syntax error is "1083: syntax error: else is unexpected".[code]No matter how or where I place the braces, it keeps giving me errors.

View 13 Replies

ActionScript 3.0 :: Use A For Statement To Create An If Statement

Jul 12, 2010

what I'm trying to do is create an else if argument for each object in an array based on a user set number

Code:
for(var i:int=0; i < numberOfElseIfs; i++){
GENERATE AS3 CODE
}

to which I want it to GENERATE THE FOLLOWING CODE:

Code:
}else if(baskets[i].used == false){
baskets[i].used = true;
drawButton(i);
}

the problem is obviously that the compiler reads this code rather than understanding I'm trying to regenerate the code within the for loop...does that make sense :S? So basically I need as3 to read the code between the for statement as if it is going to echo that out later. Is this even possible?

View 4 Replies

ActionScript 2.0 :: Flash8 Variable Set-up - 'if' Statement To Run From Variable When Playhead Encounters MovieClip

Aug 21, 2009

I want to declare a variable on the main timeline that can be called from anywhere in my movie. So, _global var should be the right approach. I want to declare a movie clip 'MC1' "open", or "closed" so that when it is revisited, my flash file knows the user has been there before and performs a different task from the one it does when 'MC1' was first encountered. So, i need a 'if' statement to run from the variable, when the playhead encounters the movieClip.

[Code]..

View 2 Replies

Actionscript 3 :: If Statement Not Working - Loop Carrera(a Lenghthy Movieclip) From Frame 2 Back To Frame 1

Nov 25, 2011

This is an if stament on a frame on the root. I want to loop Carrera(a lenghthy movieclip) from frame 2 back to frame 1. (For testing purposes) This is the code:

[Code]...

View 3 Replies

ActionScript 3.0 :: How To Pick Random Movieclip

Oct 20, 2010

but I've spent the last few days trying to find an answer to this seemingly simple question, and no luck. Well, partial luck, but not quite what I wanted.My problem is this - I want to play a random sound when an event happens. In AS2, I used to do this:Actionscript Code:s1 = new Sound();_root.s1.attachSound("sound"+(random(10)+1));s1.start();...where there would in this example be 10 sounds in the library, with names from sound1 to sound10.Now, I want to be able to do the same in AS3. As a temp solution, I've been forced to do a lot of if statements, but that's ugly, timeconsuming and inefficient.I also tried this (AS3):

Actionscript Code:
var soundArray:Array = new Array(new sound1(),new sound2(),new sound3(),new sound4(),new sound5()) var randomInteger:int var selectedSound:Sound function

[code].....

View 4 Replies

ActionScript 3.0 :: Random MovieClip Play?

Oct 29, 2010

have 16 instances of one movie clip on the stage and each  one has their own unique instance name. The movie clips have a nested  animation and I want each clip to play randomly. I'm familiar with the Math.random class, but not for animating clips.  Here is what I have so  far:
 
var turkeyArray:Array = new Array();turkeyArray[0] = turkey1_mc;turkeyArray[1] = turkey2_mc;turkeyArray[2] = turkey3_mc;turkeyArray[3] = turkey4_mc;turkeyArray[4] = turkey5_mc;turkeyArray[5] = turkey6_mc;turkeyArray[6] = turkey7_mc;turkeyArray[7] =

[code]....

View 40 Replies

ActionScript 2.0 :: Random Some Movieclip On A Flash?

Nov 26, 2009

I was thinking about create a flash that I past some movieclips on.I like to random so it spread out all over the flash.To add a a movieclip is no problem. To make it random inside the flash is no problem when I use Stage. That I have problem is that have happen the moviclip have lap over another movieclip.What I have understand I have to create some kind of array that have information about where the other movieclip is and make a zone around it so no other movieclip is close.

View 9 Replies

ActionScript 3.0 :: Movieclip Moving Random Around?

Oct 6, 2010

If I have a movieclip moving random around the stage, and I have another movieclip I one corner. is it possible to add an event listener to listen after if the random moving movieclip comes over the other movieclip?

View 1 Replies

ActionScript 2.0 :: Random Movieclip Postition?

Feb 20, 2008

How do i make it so the moviclip loads at a random X when tween starts.(but keeping it inside the stage)This is my origanl code.

Code:
mport mx.transitions.Tween;
import mx.transitions.easing.*;

[code]....

View 1 Replies

ActionScript 2.0 :: Choosing A Random Movieclip?

Sep 8, 2008

I'm trying to achieve the following:

On my stage are 8 movieclip, respectively called squid1 to squid8. I'm trying to make actionscript designate one of these 'actors' at random once in a while, and make it pop up/do something. Dont know what exactly yet. Here's what I'm working on...

Code:
function chooseActor() {
var pickNumber = (Math.floor((Math.random()*8)));
var result:Object = new Object();

[Code].....

Now chooseActor funtion does what I intend it to do, i.e. generate a variable consisting of the word 'squid' combined with a number. I expected I could simply use this variable as the name of a movieclip and then just unleash all sorts of wackiness on it. But it doesnt work.

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved