ActionScript 3.0 :: Loop Through The Buttons(movieclips) On The Stage
Jun 14, 2010I was trying to loop through the buttons(movieclips) on the stage so I can just write one functions for all of them.
[Code]...
I was trying to loop through the buttons(movieclips) on the stage so I can just write one functions for all of them.
[Code]...
i want to loop through movieClips like in AS2; i have some movieClips and Components on the stage.i want loop through them to check their properties. i had used [ getChildName ] method to get the movie clips ,but i can't access their properities.
here's my code
Quote:
for(var i=1;i<=4;i++) {
var tempisplayObject = getChildByName("my_mc"+i);
trace(temp.currentLabel);
}
when i run this code i am getting error like this
Scene 1, Layer 'Layer 2', Frame 1, Line 251119: Access of possibly undefined property currentLabel through a reference with static type flash.displayisplayObject. i am getting the same error also when i access to components.
I am reading in collection objects from an XML file. Each collection has an img field that stores a URL to the collection image. So I am trying to load the images of each collection, storing each image in a MovieClip, and add these MovieClips to the stage. However, my problem is that after adding a MovieClip (with the collection image) to the stage, when a new MovieClip is created in my 'for each' loop it overrites the previous MovieClip. So the images I am adding to the stage are being replaced by the following collection's image on each loop iteration. What can I do to avoid this?
[Code]....
I am reading in collection objects from an XML file. Each collection has an img field that stores a URL to the collection image. So I am trying to load the images of each collection, storing each image in a MovieClip, and add these MovieClips to the stage. However, my problem is that after adding a MovieClip (with the collection image) to the stage, when a new MovieClip is created in my 'for each' loop it overrites the previous MovieClip. So the images I am adding to the stage are being replaced by the following collection's image on each loop iteration. What can I do to avoid this?
Here is my code...
var collXML:XML = IXml(assets.collections).xml;
var collNodes:XMLList = collXML.children();
for each (var collInfo:XML in collNodes)
{
[Code].....
I have several buttons on stage (8), and I want to add a slighty different action for everyone of them. How do I do that, All the buttons always get the last past of the "FOR"..
Code:
function loadThumbs(eventoUrl:String) {
for(i=1; i<=9; i++) {
temp = this["thumb_"+i];
with (temp) {
image = "fotos/"+eventoUrl+"/thumbs/"+i+".jpg";
loadImages(image, temp);
temp.onRollOver = function() {
this.play();};
temp.onPress = function() {
this.loadImages(image, image_big);
};};};};
loadImages() is a LoadMovieClip type function I created.
I want to check if the stage is loaded with stuff. If it is, remove it and load my new stuff. If it isn't load my stuff.
View 1 RepliesI got the design of movieclips and others placed on the stage.And I got 1 frame for the code below.Some movieclips will be visible and not visible sometime while loading external swf files.I thinks its on the movieclips to be dynamically put on the stage.TypeError: Error #1009: Cannot access a property or method of a null object reference.
at main4_fla::MainTimeline/advantanMCs()[main4_fla.MainTimeline::frame2: 141]
at Function/main4_fla:MainTimeline/launchSWF/main4_fla:onLoadCompleteHan dler()[main4_fla.MainTimeline::frame2:46]
[code]......
It works perfectly in Flash Player 9 but not in FP10. I am calling 5 buttons onto the stage via linkage. These buttons are a movieClip with two frames inside - with different grafics on each frame. I want to use an array to make button 2 and 4 show the second frame in the movieClip. How can I do this! I guess I have to use FP10 since this is a small part of an AIR application. Create a movieClip with to frames, linkagename: radioButton, and why it doesn't work in FP10...
ActionScript Code:
import flash.display.Sprite;
var myArray:Array = new Array;
var box:Sprite = new Sprite;
var count:int = 5;
myArray = ["button1", "button3"];
stage.addChild(box);
[Code] .....
I am sure that this code can be optimized so I don't have to type 8 instances (only 2 shown) of the (almost) same code.
kabinet.onRollOver = function() {
this.fleka._alpha = 70;
this.izlaz=false;
} kabinet.onRollOut = function() {
this.izlaz=true;
[Code] .....
What I am aiming for is to have a way to pass "kabinet", or "operativni" etc. to a function or smth... The code is used to control mc buttons on the stage. It works, but it's ugly and not practical, obviously. I tried with
[var]onRollOver = function() {
Inside a function, var being the parameter of said function ("kabinet", "operativni" etc.), but to no avail. Also tried with the with(var), thingy, but with the same result.
I want to remove the movieClips created from the "for loop" and "array" from stage when it goes to the next frame. Is this line of code correct?
[Code]....
is it possible with AS3 to see the list of the movieclips that are on stage?
View 13 RepliesLooking for a way to stop all movieclips both are the stage and that are children of the ones on the stage.
I toyed with looping thru stage's children so I can first target clips on the stage. But I am getting error.
for (var i:int = 0; i < this.numChildren; i++) if (this.getChildAt(i) is MovieClip)
{
this.getChildAt(i).stop
}}
I have been using Flash since it was Flash 3 and AS2 for about 3 years now. I have never ever ever been a fan of buttons. I find them limiting and icky. I just moved to AS3 and OOP this week (it's about freakin time, I know). I am just wondering who here likes to use buttons and why? Is there a point to them? I mean, apparently with AS3, you just have to add "mc.buttonMode = true" and you are well on your way to having all the functionality you need without all the hassle or up states and all that.I am open to adopting new techniques and strategies if they are worthwhile so I am just curious as to what the community thinks. What are the pros and cons to using MovieClips as buttons instead of using an actual SimpleButton.
View 6 RepliesAn external swf is loaded using this code...
[Code]...
The problem is that even though this external movie covers the whole stage, My mouse can still "see" buttons that are on the stage, and I can click them. I don't want to be able to click the buttons through my external movie.
I've got a movieclip(we'll call this "A") on my stage, which attaches another movieclip("B") into itself. So it's nested.Now, once this movieclip("A") has attached the other movieclip("B") into itself,It uses a "gotoAndStop()" to send the frame of movieClip("B") to the right frame, eg. frame 2. Then it runs a loop which checks for all movieclips in "B" and populates an Array.The script I'm using for this is :
Code:
for (var i=0; i<h.numChildren; i++) {// This loop is suppose to populate my "bitArray" Array with all of the attached clip's childclips
if (h.getChildAt(i) is MovieClip) {[code]....
if there were 22 MovieClips on frame 2 in movieClip"B" , this code would still be able to populate my array with all 22 clips right?It doesn't. For some reason, if there were 22 clips, then out of the 22, the loop would only pick up 9. However, doing a trace with numChildren() in movieClip"B", it would still show 22. But my array would only show 9.I've attached a sample fla, I think it would explain my problem a lot better.Once you run it, it should spit out an output telling you how many movieclips in the attached movieclip, and it'll tell you how many clips it pushed onto the array.I can't seem to get the number of movieclips in my array to equal the number of clips in total inside my attached movieclip.
I use to do this in AS2, but find it impossible in AS3. The commented code is what I need to achieve through my for loop.
/*
TopIcons.btText01feedback1.visible=false;
TopIcons.btText01feedback2.visible=false;
[Code].....
I'm trying to create an accordion menu that contains three submenus. The idea is that when you mouseover one submenu (or rectangle, to keep it simple) that the rectangles which were previously covering it will move to reveal it. Menus of this type can be found at the bottom of nvidia's site [URL] for reference.
At first I tried creating each function, which will make the rectangles move, separately but this resulted in three very repetitive functions and there seemed like there should be a better way, especially since I'd like a good way to add and remove submenus. The animation did work then. I tried to clean it up by creating a for loop that would move each rectangle but now, for some reason, it doesn't work. It is still missing some key points such as utilizing the mOver variable to figure out when each rectangle is moused over and act appropriatly
[Code]...
Is there a way I can create these clips and add them to an array in a loop ? It doesn't seem to want to work for me.. ?
var p1 = new P1; var p2 = new P2; var p3 = new P3; var p4 = new P4; var p5 = new P5; var p6 = new P6; var p7 = new P7; var p8 = new P8; var p9 = new P9; var p10 = new P10; var p11 = new P11; var p12 = new P12; var p13 = new P13; var p14 = new P14; var p15 = new P15; var p16 = new P16; var p17 = new P17; var p18 = new P18; var p19 = new P19; var p20 = new P20;
I have 6 movieclips named answer1, answer2, etc. I also have a for loop where I want to assign functions to each one programatically. In my loop if I'm using var i, I wanted to refer to each movieclip with something like answer + i to refer to answer1 (assuming i = 1, for example). However, I don't know the syntax to do this.
Here's a rough shot of my code:
ActionScript Code:
for (i=1; i<7; i++) {
"answer"+i.onPress = function() {
this.startDrag();
[Code].....
I have a loop that places 5 movie clips on the stage and they all start playing at the same time. I want to see if i can use the loop variable to offset the movie clips so they are all out of sync.Delay movieclips in loop from each other?
View 2 RepliesI've been trying to use a for loop to attach a few movie clips to the stage in vain. I couldn't find any relevant examples in neither my flash manual nor the flash help nor the internet.I have a few movie clips (let's say five) that I have created manually. I want to attach them to the stage using the for loop.If I had to attach a single instance, I would do it as follows:
Code: Select allvar pic1:MovieClip = new Pic1();
pic1.x = 10;
pic1.y = 15;
[code].....
Im working on an Xbox Live flash gamercard. Ive ran into a problem. I can't position each of the MovieClips ive genereated from the loop. I get the error:
Code: Select all1120: Access of undefined property rpg0.
1120: Access of undefined property rpg1.
1120: Access of undefined property rpg2.
[code].....
I have a little problem with a loop. I recieve som data from a database and gets it back as an array. I then use a loop to add movieclips dynamicly and this works fine to, but if i try to trace the id from an onRelease function i get an undefines, but when i dot it outside the onRelease it works fine. This is the code. Its in a class by the way.
[Code]...
I have 5 movie clips, currently and I am positioning them via actionscript. The instance names are nar, mv, dance, bio, clients, contact. (pretty obvious this is navigation for a portfolio site?)
Here is the positioning I currently have...
Code:
var spacing = (((Stage.width*.75) - (nar._width + mv._width + dance._width + bio._width + clients._width + contact._width))/5);
nar._x = 10;
mv._x = 10+nar._width+spacing;
dance._x = 10+nar._width+mv._width+(spacing*2);
bio._x = 10+nar._width+mv._width+dance._width+(spacing*3);
clients._x = 10+nar._width+mv._width+dance._width+bio._width+(spacing*4);
contact._x = 10 + nar._width + mv._width + dance._width + bio._width + clients._width + (spacing*5);
Now, I know that this can be done with an array and a loop, something like, loop through all movie clips for width, then use the total in the spacing variable, then for each clip in the array, set the _x to 10 + the width of the clips before it + spacing times its array position, but man, I can just NOT figure out the syntax.
We have found that if you skip over frames that include nested movieclips with embedded timeline sounds, those sounds loop endlessly.For example, if you gotoAndStop(20) from frame 2, but frames 5-10 have a CLIP A that embeds CLIP B, which has a timeline sound, you hear that sound over and over again (even though the playback head never touched the frames with that clip).Does anyone have a convenient workaround (other than the obvious -- playing sounds dynamically, etc). For animation-sync reasons we need to use timeline sounds in this particular case.
View 1 RepliesI am new to Action Scripting 3 and am struggling to create movieclips in a for loop. Basically I am trying to create a series for movieclips and add these to my stage based on an array of values.
[Code]...
I have twenty movieclips on stage with these names:
g1
g2
g3
g4
....
How can I make invisible with a for loop, like
for (i = 1; i < 20; i++) {
g+i.visible=false;
}
This that not work.
I have done this same thing in ActionScript 3, but am not familiar with ActionScript 2, which I am forced to use for this project. I am loading products into a SWF via XML and attempting to add a click event to each dynamically-created movieclip. Simply tracing the text from a node in XML will do for now. I'd like to assign a property called "desc" or "description" to each movieclip and have it trace that property's value when clicked. Here is the relevant portion of my code as it stands[code]...
View 1 RepliesI have a bunch of movie clips on a layer named s1, s2, s3, .. s16.
I need to add them to an array so that I can select a random number to play.
Something like:
var sparkle:Array = new Array();
var i:int = new int;
for(i=0;i=16;i++)
{
sparkle[i] = 's'+i;
}
I realized that you cannot make duplicates of movieclips that have loaded images, so here I am with bitmapData to solve the trick but I cannot get it to render all the movie clips from the loop.
ActionScript Code:
XMLParser.load("resources/images/file.xml", onFinish, null, false, true);
function onFinish($success:Boolean, $parsedObject:Object, $xml:XML) {
var Items:Array = $parsedObject.item;
for (var i:Number = 0; i <= nTotalItems; i++) {
[Code] .....