ActionScript 3.0 :: Displaying A Variable In A Movie Clip?
Jan 21, 2010
I've been animating with flash for a while but I've recently wanted to get into game programing. I've learned a lot in the past month and I'm trying to create a fairly simple point and click adventure game with some basic stats and scoring. I'm facing a somewhat simple problem and I'm not sure how to get it to work in AS 3.0.
At the beginning of the flash I've established my variables to keep score while exploring the game.
var Health:Number = 1000;
var Day:Number = 1;
var EXP:Number = 0;
var Money:Number = 1000;
What I'm trying to do though is set up a movie clip with menu options that, when clicked, brings up a screen that displays those stats as well as a couple extra menu options. What I can't figure out to do is how do I display those variable inside the movie clip.
When I create a dynamic text field and place "info_day.text = String(Day);" i get an error unless I create a variable within that movie clip. And when I do that the variables in the movie clip are not affected by the chances of the variables in the main flash.
how do I have the variable in the movie clip to accurately display the variables established in the main part of the flash?
I want to display MovieClip "Loading" while loading an XML File, but something went wrong and MovieClip is displayed on the screen after the XML is loaded.the main idea is:when the Test object is added to the stage I call loadQuestions function
ActionScript Code: private function onAddedToStage(event:Event):void { event.target.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); loadQuestions(); }
it should display movie clip "loading" and load xml:
ActionScript Code: public function loadQuestions() {
[code]...
This code doesn't work as it should, because while xml is being loaded there is no MovieClip on the screen(it appears after to load is completed) [URL]
Why won't my movieclip show? I am not getting any error messages and have used to trace to make sure there are no problems but the movie clip still doesn't show.Class A calls a function in Class B.This function creates a movieclip with a basic graphic just for testing.[code]
I have 7 movie clip symbols which i would like to become visible using a timer.I would like to be able to make them appear one at a time, to a time of my choice after a 'start button' has been pressed.When the start button is pressed another movie clip already plays as a back ground.
Im learning actionscript using the tutorials here so im more interested in learning *how* rather than just getting it done.
Ive come across a problem on something ive been trying to do. Ive been trying to make a 10 framed movieclip appear at the mouse position and play continuously. To do this I have a two framed loop.
Here is my code. Circle_mc is the movie clip: ----------------------------------------------------- //this is the name of my function and what it has in it. CreateAtMouse = function () { Circle_mc.duplicateMovieClip("circlecreate", 2, {_x: _root._xmouse, _y:
It's easy to share bitmap data between multiple Images: // target and source are instances of the mx.controls.Image class var content_copy:Bitmap = new Bitmap((source.content as Bitmap).bitmapData);target.load(content_copy);
But how to do the same thing for movie clips with vector grapics? The only way I've found is to load movie clip using byte data of another movie clip as the source.
target.load(source.content.loaderInfo.bytes); But it actually duplicates the content.
I'm updating a game in a Flash, using Actionscript 2 (what it was originally built in). It's a quiz game with different categories. At the end of each test is a results page showing their score for each of all the categories; each score being saved and displayed each time it's brought up. I need to have a print button added to this page, which I was able to do with
And labeling the frame of what I want to print #p. This works, but the drawback is, I can do that on each results page frame for each category; the error that results from multiple frames labeled the same thing, 'causes the dynamic text fields displaying the score to go blank when the print button is clicked. Even if it didn't, it would still print all of the frames with that label, printing multiple copies of the same results screen. Initially I planned to tie all the quizzes to a single results page; one results page, one results frame, only one frame with the #p label, and is the only thing printed.
The problem there is, I need to be able to have a back button that goes back to a point in the category the user just finished; so they can take the test again if they want, or take another part of the test in that category. So my idea was to put all of the dynamic text fields and the print button, inside a movie clip. All the text boxes have maintained their names and have embedding enabled. All of the actionscript, on any level of that frame, has been placed accordingly into the movie clip - and yet the dynamic text boxes will not populate with the score like they do outside the movie clip.
Worst still, the print button wont work at all inside the movie clip. Clearly I'm missing something, but I can't be that far off base in thinking this would work, am I? If I can make the movie clip show the results and work the print button, then I can use instances of the movie clip in as many frames as I need, but the only place the script or label for the print button will exist, is inside the movie clip. This is the script for the button putting the data into the text fields.
In my project are pages of text with each word having a button that when pressed will display a movieclip presentation about that word (its pronounciation and spelling etc..). In the project I am working on now I have over 450 unique presentations of words to deal with. I don't want to have all of these hundreds of movie clips on the stage and tell them one at a time to stop and rewind and then have one play each time a word button is pressed. That seems to be very inefficient to me.
add movieclips to the stage using addChild(movieclipname) and remove them using removeChild(movieclipname) but there is a problem. I have hundreds of unique movieclips and I don't want to have to manage hundreds of variables containing the indivudual movieclip instancess. It is a real pain having to figure out what instance is still on the stage before i delete it.In Adobe Director all I have to do is this:
On frame 1 of the main timeline I have a movieclip. The 1st frame of the movieclip stops, and requests a password. When the password is correct, the movie clip plays and stops again on frame 2 - where the user enters their name. I've named this variable 'name_txt', and the submit button will only continue if the variable is defined.
The problem comes when I try to get a dynamic text box in the main timeline to show the user's name - it just stays blank even through i've experimented setting the var / instance names to 'name_txt'. I think I have to set the variable to global or something, but cant seem to get it to work.
I've got a simple ActionScript 1 FLA. The SWF will take incoming variables from SWFObject. e.g. txtVar01, txtVar02, txtVar03 On the first keyframe on the main stage, I have a dynamic textfield, whose 'Variable' name is 'txtVar01'. When I view the SWF in a web page, via SWFObject, the value in the textfield matches that taken from the SWFObject variable. BUT - I have a MoveClip in the FLA, which has 2 other dynamic textfields, called txtVar02 and txtVar03.
When I view the SWF in the web page, these are empty, even though variables are being passed via SWFObject. I guess because the dynamic textfields are within an MC and not on the main stage, they can't access the variable names. I tried adding this to the first frame on the stage:
I have been using this line of code to fade in a movie clip:
new Tween(background_mc, "_alpha", None.easeNone, 0, 100, .5, true);
Now, I want to accomplish the same thing, only this time by using an element from an array (bg_array[currentSlideNumber]) that stores the instance name "background_mc"
I've tried the following, but it doesn't work:
new Tween(bg_array[currentSlideNumber], "_alpha", None.easeNone, 0, 100, .5, true);
I found this tutorial which seems to do exactly what I'm trying to do (the only one I've found to date), except his technique doesn't seem to work for me at all. It doesn't really seem to say anywhere which version of Actionscript he uses, but at least it seems to show that what I'm trying to do is possible for someone, which is a start.I'm trying to do exactly what he describes--I have several squares on a grid that are numbered, eg.grid_0101, grid_0102, grid_0103, and so on, for about 100 squares altogether, and I want to be able to target a given square dynamically.This is the basis of the code I started with:
Code: var digsquare_x:String = "01"; var digsquare_y:String = "03";
i am doing a photo album type site where all photos (which are movie clips) appear small and when clicked they enlarge. when the enlarged photos are clicked the movie clip continues and they go small again.
as you'll see from the code below i am doing this by basically saying if the photo is small, play the movie clip from frame 2 which enlarges it until a stop value at 30, and then change the variable value. if the photo is large and then it is clicked play the movie clip from 31 to a stop action at the end and then change the variable value.
everything is working fine except i am not receiving the initial value of the variable "picbtn_position" which is set on the main timeline to value "mainscreen". can anyone help me as to what is going wrong here? maybe i have to do something else to get a variable value from the main timeline to the mc.
here is the code on my movie clip:
on (release) { if (picbtn_position == "mainscreen") { trace(picbtn_position); gotoAndPlay(2);
[Code]....
and here is the code on my main timeline for the initial variable value:
I want to use a variable in my movie clip code. Right now I generate a random U.S. state name and assign it to "correctAnswer". Then I want to assign that to myMovieClip.correctAnswer.gotoAndStop("down"); The problem is that the variable is not recognized and is seen as correctAnswer instead of the U.S. state that was assigned to it. My code is below.
ActionScript Code: // Correct answer is randomly generated and can be any U.S. state name correctAnswer = "utah"; // Using the variable correctAnswer this should come out as myMovieClip.utah.gotoAndStop("down"); myMovieClip.correctAnswer.gotoAndStop("down");
I want to cycle through several movie clips for a training application. I plan to use an array to hold the clip names, and a variable (CurrentClip) to set visibility and allow me to use a single pause/ play button throughout. For the visibility, I've found that... CurrentClip._visible = false; does NOT work. But... setProperty (CurrentClip, _visible, false); does work.
how to refer to a movieclip's name through a variable.If I set root variable "currentMovie = bigRed_mc;", how can I use that variable name to instruct the movie to address the movie clip name stored in said variable?
for instance "_root.currentMovie.gotoAndPlay("destroy");" wouldn't work because it would simply look for that movie clip name and come up empty.I thought "_root[currentMovie]gotoAndPlay("destroy"); would work, with or without parenthesis, but it comes up with syntax errors either way. Can you use a variable to store and refer to a movie clip name and it's properties?
In AS2 I used to be able to reference a movie clip using a variable like this: Code: var target = nameofmovieclip; I've been looking for an answer on how to do the same thing AS3 but with no luck. I'm trying to create a dynamic homing missle, but unfortunately everything I've tried just generates errors.
I couldn't find anything with Google on how to do this, so I'm posting it.I have a code on the first frame of a movie clip that goes to and stops at a different frame in the movie clip depending on a variable that was set outside of the movie clip. It doesn't work, and the movie clip just plays through like normal
I have a movie clip that is executing some code. When this code is complete, I want it to change a variable that is defined on the stage (root?). I know how to get the condition part of it, but quite literally: what do I put to change a variable located on the stage from within a movie clip?
I have a flash file which uses php to manipulate a database and returns a variable (data_xml) of xml formated data from the database. This happens, along with other things, within the parent. Now I have a child movieclip that displays the parsed data but I am having trouble accessing the variable from within the child movieclip. The code related to this is:
var myXML:XML = new XML();var myXML = XML(event.currentTarget.root.data_xml);
and I get the following two errors which point to the second line as the problem:
1151: A conflict exists with definition myXML in namespace internal.
Warning: 3596: Duplicate variable definition.
I have unchecked "Automatically declare stage instances" because I've seen that suggested for the 1151: error, but I still get the same two errors.
I have been searching for ages and just cant find out how to do this. i have set a boolean variable inside a movieclip and would like something to change outside the movieclip, using an if statement, depending on whether the variable is true or false, but cant find out how to do it anywhere.
(problem 1 is that I cannot call buttonmoce this way!)I am really trying to imporve my code writing and using arrays and for will save me writing this code over and over again Cheers sub
how to add a movie clip to the stage from the library but i'm strugling to do it when the I need to load a movie clip from the library when the name of the movie clip is held in a variable.
for(var i:Number = 0; i < 64; i++) { var blueIconS:blueIcon = new blueIcon(); addChild(blueIconS);
[Code]....
The above code works for adding the blueIcon but I have a variable in that loop which tells which icon to load.
sectorsMCs[jewelsIDs[i]]
The above will tell me what MC name to load but how do I load a MC from library by that variable value?
I have been struggling with what I suppose is a very simple issue: I am importing content into my application via a text file, this all works fine. I have about 10 different movie clips on the parent timeline that I have hidden (dc_mc.visible = false.So what I need to do is take one of the variable names that I've got from my text file and use its value to "turn on" one of these hidden movie clips.So I'm trying stuff like:
var directory = e.target.data.directory; // Grabs the data, sets var var raceNameButton:String = directory+"_mc"; // Set data into new var raceNamesButton.visible = true; // display movie clip with var name
Is there any way to dynamically name a varaiable or created movie clip? I know that I could make an array of movie clips, but what I really want to do is make a new movie clipe name based on another name. The reason I want to do so is that I want to pass a movie clip to a function and have it make a new movie clip (to contain the first) with a slight variation of the test such as "frame" or "handle" which I can then use to center the source movie clip.
I have a big bit of action script that I want to reuse on various frames. Rather than write it out on each frame I want to embed the script within a movie clip and embed that movie clip on each frame that it is required to be used on.
In order to do that I need to pass a different value into the movie clip.
Basically the script creates 20 pages on one frame, 40 pages on another frame and 60 on the last page.
This is the bit of code that needs to have the number fed to it:
ActionScript Code: var myArray:Array = newArray(20);
The number 20 is currently set manually. I ideally want to write this within the movie clip:
ActionScript Code: var myArray:Array = newArray(frameVal);
and on the stage I want to set the variable like this:
Frame 1:
ActionScript Code: var frameVal:Number = 20;
Frame 2:
ActionScript Code: var frameVal:Number = 40;
Frame 3:
ActionScript Code: var frameVal:Number = 60;
The movie clip that contains my code has an instance name of "testStart"
how do I get it to pass the frameVal into the movie clip?