ActionScript 3.0 :: Assigning Unique Variables To Movieclip Instances?

Apr 10, 2009

When one creates several instances of a movie clip on the main timeline, how can one assign separate variables to each of these instances and then invoke each of these values from the main timeline? I know how to do this by creating a separate movieclip and putting code on that movie's timeline (using 'this'), but I always feel this is sloppy because I'd like to keep my code all on one timeline.Here's some example code. It creates three instances of a movie clip, and assigns each one a variable called 'contImage' which contains the source of the loaded image. How can I get this variable traced when each of these images is clicked?Even though, as I said above, I have a work around, it has stuck in my craw for a while now.

Code:
var photos:Array = new Array('images/1.jpg', 'images/2.jpg','images/3.jpg');
for(var i:int = 0; i < photos.length; i++)

[code].....

View 6 Replies


Similar Posts:


ActionScript 2.0 :: Using Variables As MovieClip Instances?

Jan 14, 2006

I'm having some trouble trying to duplicate movieclips randomly. I have created an array with the instance names of the MCs i have on stage. Then I'm trying to create a variable that selects one random element from the array. Finally I want to use that variable as a target to duplicate my movie Clips... but it doesn't work.

Here is the code:

Code:

var Items = new Array('bombon', 'regalo', 'corazon');
pos = new Object();
pos._x=random(550);

[Code]....

View 5 Replies

ActionScript 2.0 :: Defining Variables - Unique To Load SWFs Instead Of Declaring All The Variables

Mar 21, 2012

I have an empty SWF that's sole purpose is to call loadMovieNum and start the project. Each loaded movie has a few variables defined within them - unique to those loaded SWFs. Instead of declaring all the variables in each SWF can I declare all of them in one place, in the first frame of the empty loader it all starts from? I'm thinking I can then declare a variable which each loaded movie can increment as needed for me.

View 2 Replies

ActionScript 3.0 :: Access Relative Variables Of Movieclip Instances From Root Or Other Movieclips

Feb 1, 2010

In AS3, how can you access a relative variable within a specific movieclip on the stage?I have a test file that changes the variable "myVar" in one of the displayobject movieclips drawn on the stage. I want to simply trace the current value of this displayobject's myVar for additional purposes.In AS2, you would achieve this by calling the instance name and then the variable contained within.Assuming 3 movieclips existed on the stage named Container1¯, Container2¯ and Cotainer3¯trace(_root.myContainer2.myVar);// returns Hello which is value of variable "myVar" within the movieclip instance named "Container2".How would you do this in AS3?[code]

View 6 Replies

ActionScript 2.0 :: Game Project - Placing Unique Instances Of Enemies On Screen

Mar 23, 2010

I've been working on a uni project. Basically, enemies are placed on the screen using a timer variable and using the attachMovie to put them on the screen. This is an example of the code I'm using:

Actionscript Code:
var enemies;var timer;
function onLoad(){
enemies = [];
timer = 0;}
function onEnterFrame(){timer++;
if (timer == 10) {
Timer = 0;
var enemy = _root.attachMovie("mc_1", "mc_1",
_root.getNextHighestDepth());
enemies.push(enemy);
}}

This works and places them on the screen, (and into the array) but by putting them into the array, I thought that each one would be a unique instance of the movieclip which doesn't always seem to be the case. If I shoot one of the enemies, sometimes another enemy will explode (or both of them) and other times I will knock into one enemy and another one will be the one who get's knocked.

For my collision code I'm using this:
Actionscript Code:
for(var i in _root.player.enemies){
if (some arguments..)
_root.player.enemies[i].health -= 10;
}}
The explosion code also uses a similar for loop. Should I look at another method to place unique instances of the enemies on the screen?

View 3 Replies

Actionscript 3 :: Flash Assigning The Same Code To Multiple Instances

Mar 4, 2011

im new to flash actionscript and i am trying to create a very simple game. in this game i have about 50 walls that i want to stop the player if they collide with it. i cant figure out how to assign the same code to multiple instants and im still fuzzy on alot of the terms flash programmers use but im learning.on an unrelated note i am also having the player push the ball and when i add a collision.block to the ball when it hits the wall it goes right through it because of the ball repositioning itself based on the players location.

View 1 Replies

Actionscript 3.0 :: Assigning A Function To Lots Of Button Instances?

Jun 7, 2011

How can I assign the same function to lots of different buttons with different instances names? ie the following function needs to be assigned to all my "correct" buttons. ie, correctansnwer1, correctanswer2, etc etc.

Code: Select allObject(this).mainquestions.CorrectAnswer1.addEventListener(MouseEvent.CLICK,correct);
function correct (event:MouseEvent):void
{

[code]...

View 1 Replies

ActionScript 2.0 :: F8 Giving Variables A Unique ID

Feb 28, 2010

[code]i know about arrays and the code above isn't what i got its just a way to try and explain it a bit better.I would like to know for a TD game i am trying to make

View 2 Replies

AS2 :: Create Unique Variables In For Loops?

Nov 12, 2010

I'm wondering if it's possible to create variables in a for loop that uses an incrementing number in the variable name.
 
This is the code I've tried (as a long shot) but isn't working:
 
var i:Number;for(i = 1; i < 10; i++){  var ["number" + String(i)]:Number = i;}
trace(number5);

What I'm trying to create here is a series of variables called "number1", "number2", "number3", etc. Is there another way of doing it? I'd need them to be public (I think that's the term?), so they can be used elsewhere in the script.

View 3 Replies

Professional :: Create Unique Variables In For In Loops?

Sep 3, 2010

I have an onEnterFrame function controlling all the movie clips in an array. The motion of each of these movie clips is controlled by a few variables speed, acceleration, etc that are modified on each enterFrame. I can't figure out how to create unique variables for each element in the array. At the moment my variables are the same for all the elements, and so the motions for each movie clip are the same.

I have used this code to add my movie clips into the array:
 
for(i = 0; i < starNumber; i++){ duplicateMovieClip(star, "star" + i, i);  starArray.push(this["star" + String(i)]);  }

Do I need to do a similar thing to create unique variables for each? Or is there something I need to do in my for(myClip in myArray) loop that is contained in my onEnterFrame function?

View 4 Replies

Flash - Iteratively Create Unique Variables?

Jun 9, 2011

Can you use a

for(x:int=0; x<100; x++)
{
var varname+x:Type = (x, something, something);
}

To create one hundred unique variables? Basically I need to make 100 variables and am wondering how you create 100 vats with out resorting to Declaring them all by hand. the problem is var whatever+x just creates a variable with whatever+x instead of creating whatever0, whatever1... to whatever99.

View 1 Replies

ActionScript 3.0 :: Assigning Flashvars To Variables?

Jan 16, 2009

I am using swfobject v2.1 to pass flashvars to my swf and I was wondering what the best or preferred way to pass those flashvars values to AS3 variables inside the swf.

snippet of javascript inside my html file from swfobject's required code.

Code:
....
var flashvars = {};
flashvars.myVar1 = "one";
flashvars.myVar2 = "two";

[Code].....

I essentially want to be able to pass a handful of flashvars to my swf and assign their values to AS3 variables inside (such as flv file url, skin, background colors, autoplay true/false, etc... my approach would be that certain AS3 variables would have default values (realizing my above examples do not show this), while others would require them passed from Javascript (flashvars).

View 2 Replies

ActionScript 3.0 :: ArrayCollection - Assigning Keys From Variables

Jul 16, 2010

I'm constructing an ArrayCollection that I want to be completely dynamic. I do not want to hard-code in name/value pair values to create it. I've written up a program that grabs some XML from an exterior source and then assigns values from it. The ArrayCollection is being used as the source for a chart.

This example works, but is not reuseable:

ActionScript Code:
projects = new ArrayCollection([
{Project:"On Time", Percentage:60},
{Project:"On Time With Developer Exception", Percentage:20},

[Code]....

and the expected values are assigned in the [0] members of the variable structure. Basically it's the exact same thing, but with the values buried a level deeper. So my question is in two parts. The first is a plea for general help with this problem. The second part is in regards to the ArrayCollection's addItem function. Is it required to hard-code in the keys to the ArrayCollection? That severly limits its usefulness. Since the key appears to be interpretted as a string, even though it's assigned without double-quotes, I would think that a string variable could be used instead.

View 1 Replies

Data Integration :: Assigning Loaded Variables Using Loadvard?

Jun 27, 2007

i am using loadvars to load url encoded data from a php file.

when i trace the output it shows that the variables have been retrived successfully.

now i need to use the values by assingning then to a variable. i cant seem to get this going

i am using flash 8 with as2.

myVars.onLoad = function (success) {
if (success) {
trace (" variables loaded ");
ad1id.text = myVars.ad1id;

[Code].....

is the above method used for assigning the variables correct.

View 1 Replies

Flex :: Flash Builder - Not Assigning Data To Variables?

Mar 4, 2012

I am trying to assign a value from my database to a variable inside my Flex application. So far I read up a few ideas and I have at the moment the following code using a PHP web service:

protected function btnSubmitUser_clickHandler(event:MouseEvent):void
{
username = txtUsername.text;

[code].....

View 1 Replies

ActionScript 3.0 :: Assigning Variables To Specific Objects On Stage?

Jan 3, 2010

I may just be forgetting something really simple here but I'm stumped.I have 2 guys on the stage.I want one guy to do a certain amount of damage and the other to have a certain amount of health. The problem comes from having hundreds of guys coming and going and they all need to have stats attributed to them.I don't know where I could store those variables so they can be referred back to in the code. The guys on stage are all named guy1, guy2, etc. and it would be nice if there was a way to just say guy1.health and guy2.damage and store the variables in the objects themselves somehow.

Also, I already tried putting "var health = 10" in the actual objects in the library but for some reason it takes 2 or 3 frames in game for the code to call those variables from inside the object and it causes a lot of problems. Am I missing some much easier way to do this?

View 3 Replies

ActionScript 3.0 :: Assigning Variables Into Dynamically-created MovieClips And Indexing Them

Apr 27, 2010

I'm having a problem while assigning variables into dynamically-created MovieClips. Here's a pseudo-code of what I'm trying to achieve.

[Code]....

I need the movie clips to contain their index values as a variable within them. I've tried several approaches, including declaring the variable names within the MC itself, but that doesn't work either.

View 2 Replies

ActionScript 2.0 :: Creating Variables In A Loop And Assigning Them Non Empty XML Values

Jun 1, 2011

Here is the structure of the XML file: PHP Code: <xmlfile><page></page><page> <source></source> </page></xmlfile> Some "page" nodes contain the extra "source" node. What I'm currently doing is looping through all the page nodes and looking for any source nodes. If there is a source node, I create a variable, and want to assign it a value of the contents of the "source" (HTML).

[Code]....

View 1 Replies

ActionScript 2.0 :: Assigning Movieclip To Dynamically Created Movieclip

Oct 24, 2006

In part of my actionscript i'm using: thumbnail_mc.createEmptyMovieClip("t"+k, thumbnail_mc.getNextHighestDepth()); to create a seperate movieclips for ewach image in my xml file. How would I then attach another movieclip to each of the newly created ones? ie thumbnail_mc.t0, thumbnail_mc.t1, thumbnail_mc.t2... is there a way to do it automaticall7y or do i have to assign it to each one individually? "thumbnail_mc.t"+k.attachMovie obviously doesn't work

View 11 Replies

IDE :: Calling Movieclip By Id In A Unique Way?

Jun 6, 2009

I am trying to make a multiplayer card game which has 6 players. Each player can hold 2 cards.

The movie clip names are :
p1c1 // Player 1 card 1
p1c2 // Player 1 card 2

[code].....

View 2 Replies

ActionScript 3.0 :: Flash - Unique Class For Each MovieClip?

Oct 13, 2011

This is what I am trying to do. I have a "n" number of dynamicly loaded movieclips (ships).ach ship has a unique movement throught points that I also load from an xml file.For example "Ship A" will go to x:100 y:120 then to x:200 y:300 and so on. Ship B has a diffrent set of points that will travel. I know how to make this work for one movieclip(ship). I was wondering if I can use the same "movement" class for all of them? What values should I pass to the class exept the movement array of each ship

View 4 Replies

ActionScript 3.0 :: Printing Frames (with Unique Pages) Of MovieClip

Nov 16, 2011

Code
var clipAImprimer=new ClipToPrint(); //In my library
var myPrintJob:PrintJob = new PrintJob();
if (myPrintJob.start()) {
For(var i=0; i<clipAImprimer.totalFrames; i++) {
myPrintJob.addPage(clipAImprimer, null, null,i);
} myPrintJob.send();
clipAImprimer=null;
}

I try to print all frames of a movieClip where each frame is a unique page. My movieClip have 3 different frames. The result is that I have 3 pages, but it's printing only the first one. I tried to call
myPrintJob.addPage(clipAImprimer, null, null,1); and
myPrintJob.addPage(clipAImprimer, null, null,2);
to make a test and it's the same result. I confirm that my clip has 3 different frames. I tried too label #p each frame but it's not effective for PrintJob. I have Flash CS4 and I can't use Flex, Air and Catalyst.

View 7 Replies

ActionScript 3.0 :: Create Unique Movieclip Tree From An Instance?

Jul 2, 2011

I have a structure of movieclips, which is something like:

Top Level: My character's collision movieclip, stickman_root

Second Level: On each frame of the top level, the visual part of the character, in a different pose. stickman_stand, stickman_walk, etc

Third level: in each of the poses in the second level, the character itself is built of several smaller movieclips. stickman_head, stickman_torso, stickman_upperarm_l, etc...

So having created this structure, I'd like to be able to use it as a template. I'd like to turn an instance of the toplevel into a new, unique library symbol, and similarly everything under it should also get a new unique symbol, so I can modify those as needed without messing with my template. So that I can take this stickman template, and change the graphics to create someone less stick-ish, while still retaining the skeleton and animations I made. Create unique movieclip tree from an instance?

View 3 Replies

ActionScript 2.0 :: Targeting Instances With Variables

Jul 9, 2009

I am working on building a menu of seven buttons (movieclips). When you click on one, it turns it blue. When you click on another one, the previous one needs to revert back to green.What I'm doing is, when you click on the buttons... it loads a number (1-7, depending on the button) into a global variable (menuActive). That variable is then referenced to check which button needs to be turned green when you click on the next button.[code]I have two problems:

1) It doesn't seem to be appending the value of 'a' to the targeted instance name correctly. (If I replace _parent.mcBtn+a with _parent.mcBtn7, for example, it works fine.)

2) It also seems to be keeping the "this.gotoAndPlay("btnOn"); parts from working properly.

View 3 Replies

ActionScript 2.0 :: Validate Value Before Assigning To MovieClip TextField

Apr 15, 2010

I have a movieclip with a textfield with its variable property assigned to an external variable. I need a way of knowing when the value has changed to perform some actions, and also if possible to validate the value before it is assigned to the textfield. Is there a way to acomplish both this tasks in AS2?

View 7 Replies

ActionScript 2.0 :: Assigning Actions To Dynamic MovieClip?

Mar 31, 2005

Assign actions for a mc created dynamically?

View 3 Replies

ActionScript 3.0 :: Assigning X And Y Coordinates In Dynamic MovieClip

Jan 11, 2010

I cannot assign _x and _y coordinates in a movie clip dynamically. For example:
for (i=1; i<=5; i++) {
myThumb_mc = "thumb" + i;
myThumb_mc._x = Stage.width/2;
myThumb_mc._y = Stage.height/4;
}

But if I do:
thumb1._x = Stage.width/2;
this works.

View 3 Replies

ActionScript 3.0 :: Assigning String To Movieclip Name Then Calling It?

Dec 1, 2010

So I'm having trouble calling my movieclips that I created and assigned strings to their names.So I'm trying to create 3 movieclips with 3 different instances and add them to the stage.here's the code:

for(var i:int = 3; i > 0; i--){
var myMC:MovieClip = new MovieClip();
var myMCName:String = "MCName"+String(i);

[code].....

View 3 Replies

ActionScript 2.0 :: MovieClip Animation Stops After Assigning Instance Name

Sep 22, 2009

I have an all flash website I am finishing. On the "index" page of it, there are 7 buttons all pointing to different painting galleries on another page (or another MC in this case).

These 7 buttons happen to be movieclips so that I can have animation on rollover and rollout. A sample of the current AS2 code for them is below:

on (rollOver) {
gotoAndPlay("s1");
}

[Code]....

In this case, on the index page there is a movieclip with successful animation on rollover/rollout. I assign this clip the instance name of "gallery0" and when clicked, goes to a separate page showing the first gallery.

My problem is this, whenever I do assigned the instance name to any of the 7 movieclips, the animation no longer works. It simply sits there in the default state and acts as it should as far as navigation goes.

View 6 Replies

ActionScript 3.0 :: Assigning Actions / Animations To MovieClip Buttons?

Mar 18, 2011

I am following along this tutorial: [URL]. And I get to the part where I need to add code to get my buttons to work, and I copy and paste the code and then change the frame labels to match mine, but then I get a syntax error:
"About_Project_mc, Layer 'hit area', Frame 1, Line 1
1086: Syntax error: expecting semicolon before leftbrace."

View 4 Replies







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