Using Loop Variable To Target A Series Of Text Fields On The Stage
I have a series of text fields that I manually put on the stage and I'm using them to show answers in a quiz. Their instance names are answer1, answer2, answer3, and answer4. I want to use a loop to push different text strings to each answer text field, and I'm trying to figure out the best way to do this in AS 3.0. Here's how I would have done it in AS 2.0.
for (i=0; i < 4; i++) {
this["answer"+i].text = arrayOfText[i];
}
Someone was kind enough to tell me in my last post that this type of variable concatenation in a path does not work in AS 3.0. He suggested I store the text fields in an array using some code like this:
var myAnswerFields = new Array(); for (i=0; i < 4; i++) {myAnswerFields.push(new TextField()); myAnswerFields[i].text = arrayOfText[i];}
So, I have two problems with this suggestion.
#1: What if I don't want to create the text fields dynamically? What if I don't want to use addChild to put them on the stage and I just want myAnswerFields to store the instance names of my text fields that I've already put on the stage "by hand?" I tried pushing string values to the myAnswerFields array with something like push("answer" + i), but then Flash thinks I'm trying to modify the nonexistent .text property of a string inside the array, not modify text in an existing text field of with the same name as that string.
#2: If I was willing to add the text fields dynamically, how do I give them instance names when they're created? The example above just creates some new text fields and puts them in an array, but they're never given instance names as far as I can tell.
FlashKit > Flash Help > Actionscript 3.0
Posted on: 10-18-2007, 06:13 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Setting A Series Of Text Fields In A For Loop
Hey, I'm trying to use a For loop to set the value of a series of text fields from a DataSet (my_ds). Basically they are all embedded in a series of sequencially named movie clips. I'll post the code I'm using below. Thanks for the help.
Code:
my_ds.first();
for (i=0;i<my_ds.length;i++){
catTitle = String("lesson_mc.cat"+i+"_mc.title_txt.text");
setCatTitle(eval(catTitle)); //should send the value of catTitle
my_ds.next(); //moves to the next record in the DataSet
}
function setCatTitle(path) {
path = my_ds.Cat_Name; //should set passed text path to proper value, but does not.
}
Creating A Series Of Text Fields In MCs
Hi, I must be doing something rather simple wrong. I am trying to generate a series of MC each with a text field whose value I can set. Instead I am getting a single one bouncing around the screen. I have done similar things with other objects, but I guess there must be something going on with the text fields???
I would appreciate help.
Here is the test code I am using -- the actual development would follow fixing this.
var obNum = 0;
function makeText() {
obNum++;
var newObject = "myOb"+obNum;
trace(obNum);
createEmptyMovieClip(newObject, obNum);
with (newObject) {
createTextField("newText", 0, 0, 0, 100, 100);
newText.text = "monkey"+obNum;
trace(this.newText.text);
}
this._x = Math.ceil(Math.random()*300);
this._y = Math.ceil(Math.random()*300);
}
volumeInterval = setInterval(_root, "makeText", 250);
Target Text Fields
I am trying to figure out how to control text fields objects. I have a project that I am working on here that the text is dynamically loaded from XML inside a "button" if you will, and I have a simple MOUSE_OVER so that the button tweens. Problem is, the text is screwing it all up so I disabled the text using selectable = false. The project works.
Now I have another problem, I have to be able to make the text selectable on MOUSE_DOWN so that users can copy the text and then have everything return to non selectable at some point. Im just having a horrible issue with this. If anyone could help I'd really appreciate this and thanks in advance.
How Do I Target A Series Of Frames?
Hi,
Can someone help me--I need the user to click the mouse during a specific series of frames (5-8) of a running 20 frame timeline of a movieclip. If the user clicks during that series of frames, the textbox will read "Good Job," or something. However, if the user clicks before (1-4) or after (9-20) that series, the textbox reads "You Missed," or something.
The event handler is a simple button set to On Release.
Thanx for any help.
Caremerger
Create Text Fields Using A Loop
Hello!
I need to use createTextField method for an application.
I hope you can tell me if the following can be done with for loop or in other shorter way?
ActionScript Code:
this.createTextField("opt1", this.getNextHighestDepth(), 0, 0, 200, 20)
this.createTextField("opt2", this.getNextHighestDepth(), 0, 30, 200, 20)
optArray[0] = opt1
optArray[1] = opt2
I need this optArray, because later I need reference for each textfield.
Any comments are welcome.
Thank you!!!
PS:It should work in flash player 7
Using A Loop To Set A Series Of Properites
I've got a series of 8 option buttons, and I want to set the buttons labels ad data values based on an array of the values loaded from XML based on the index selection of a list box. The 8 radio buttons have instance names of option1Button, option2Button, option3Button, ... up to 8, and I have an array for each of the files I'm dealing with for each of the options, so there is option1Ar, data1Ar, option2Ar, data2Ar, etc.
Now based on some things that were posted in some other threads about evaluating, I figured I could do something like this:
Code:
for (a=1;a<9;a++){
["option"+a+"Radio"].label = ["option"+a+"Ar"][indexNumber];
["option"+a+"Radio"].data = ["value"+a+"Ar"][indexNumber];
}
rather than:
Code:
option1Radio.label =option1AR[indexNumber];
option1Radio.data = value1Ar[indexNumber];
option2Radio.label =option2AR[indexNumber];
option2Radio.data = value2Ar[indexNumber];
option3Radio.label =option3AR[indexNumber];
option3Radio.data = value3Ar[indexNumber];
option4Radio.label =option4Ar[indexNumber];
option4Radio.data = value4Ar[indexNumber];
option5Radio.label =option5AR[indexNumber];
option5Radio.data = value5Ar[indexNumber];
option6Radio.label =option6AR[indexNumber];
option6Radio.data = value6Ar[indexNumber];
option7Radio.label =option7AR[indexNumber];
option7Radio.data = value7Ar[indexNumber];
option8Radio.label =option8AR[indexNumber];
option8Radio.data = value8Ar[indexNumber];
But I just can't seem to get my head around it and can't find anything in the help files that makes how to do this seem any easier.
Can anyone explain this clearly?
Variable In Text Fields? Plz Help
I have made a movie and used duplicateMovieClip and made 6 instances name pie1 through pie6, I have 2 text fields in them and I want the textfields to display different variables out of the root. for example:-
in root:
clientName1 = "Client1 Example";
clientIngress1 ="Example Text";
clientName2 = "Client2 Example";
clientIngress2 ="Example Text";
How would I make it so in pie1 the 2 text fields show clientName1 and ClientIngress1 and pie2 showed clientName2 and clientIngress2
Please help
Many thanks
m00p
Variable Text Fields
Hi,
I have tried to work this out for quite a while now.
I have some dynamic text fields in my movie.
if (language == "danish") {
myVar = "TEXT IN DANISH";
}
if (language == "english") {
myVar = "TEXT IN ENGLISH";
}
now once i start my movie the text field is set to danish.
I have a button which Ive called english and its actions are
on (Release) {
language = "english";
}
but the thing is that the text doesn't change into english once I've clicked the button?
I would be gratefull for any help?
Control A Series Of Buttons With An AS Loop
I have a series of 10 buttons. I want the buttons to be able to "automatically" click, as if the user is clicking them with an interval of 1 second in between the clicks. Is there a loop that I can use to keep these buttons firing, one after the other with a second of time in between ?
Load A Series Of Images With 'for' Loop?
Kind of new to AS3...
can someone give me some advise on loading and displaying a series of images using a function that contains a 'for' loop?
I'm not using XML. Just a bunch of images with incremented names - img1.jpg, img2.jpp, img3.jpg, etc.
I know how to write a looping statement... I understand the URLRequest and Loader class, display list, addChild, event model, etc...
What I'm not sure about is the best way to loop through a series of URLRequests and load all of them in a row. Would I create a new URLRequest for each? Would I make a new Loader instance and increment its name using the for loop (myLoader[i] or whatever...)?
Does this make sense?
How To Associate Same Actions To Series Of Objects In A Loop?
What I mean I dont want to open the actions panel for every object a a long series with the same actions and use cut and paste.
I need to associate the group of actions (on (press), on (rollOver), etc), the same, to a group of objects by referring to a compact source (file?, function?)
Thanks
'get Variable' Text Fields Made Transparent?
Y'know when you make a text field or text box editable for
use with 'get variables from a .txt file' and the box
becomes white as opposed to transparent?
There must be a way around this so it can fit seemlesly into
your site of a different colour? no?
Version 4 that is.
If not, can other versions of Flash support this??
thanks
Variable Instance Names For Text Fields?
I am wondering if it possible to create a unknown number of objects and give them instance names using variables and then refer to them using other variables. For example, create n text fields named field_1 through field_n and then assign text to them somehow using field_var. I'm trying to make a calendar that displays the current month based on system time, though I can think of a great many other uses for this kind of thing. I'm just not at all sure how to go about doing this or if it is even possible. It seems as though it should be. If this isn't clear enough let me know and I shall try to explain myself a bit better. I was able to do the following but there were issues:
Code:
for (i=1;i<31;i++)
{
this.createTextField("date"+i+"_txt",1,thisX,thisY, 50, 50);
}
The first problem I have with this is that later on I cannot do this:
Code:
datei_txt.text="whatever";
and to boot, when I ran the debugger it turns out it doesn't create 30 instances, it just keeps destroying the previous one and replaceing it with the new so that at the end I only have one field with an instance name of date30_txt.
So how can I create this effect in a different manner?
Thanks in advance,
~NH
[edit] I had another though aswell, createing an array of text fields, but I can't figure out how to create a text field within one element of an array object so that I can refference them through the array's index.
Dead Easy Q - Key Press Loop Though Image Series?
my aim is to use Left/Right keys to loop through a series of images. i need some help with the looping aspect of this.
i.e if there are 5 pics, how do i get it to go "Right" from 5 to 1, and "Left" from 1 to 5.....?
Code:
// use arrows to navigate
this.navKey = function() {
if (Key.isDown(Key.LEFT)) {
PicNum -= 1; // image
trace("you pressed LEFT");
}
if (Key.isDown(Key.RIGHT)) {
PicNum += 1;
trace("you pressed RIGHT");
}
}
setInterval(this,"navKey", 100);
Targeting Variable Text Fields In Movie Level 1...
How do I target a dynamic text field called 'box_text' sat in a movie clip called 'mouse' that is in a movie 'mouse.swf' I have loaded into level 1?
I need to be able to update the text within a mouse tool-tip / help box as it rolls over a diagram. The loaded movie clip is loaded in level 1 and all of the dynamic text box and surrounding graphics is within a movie clip called 'mouse' that is dragged around the screen by the user.
At the moment I am using:
with (_level1) {
mouse.box_text = "Welcome";
}
Only 1(of 2) Text Fields In Custom Component Defined By Variable Is Always Blank-why?
Hi,
I have made a custom component in Flash MX 2004, and all it has right now is two dynamic text fields whose content is defined by a variable, and a link whose url is defined by a variable also.
I enter the values for these variables in the parameters area of the properties window, but when i preview my movie, the only thing that shows correctly (i.e. has text in it) is one of the two text fields...the other is blank.
I have uploaded my fla at this address:
http://www.lucid-life.com/my_component.fla.zip
Is anyone able to see what I'm doing wrong?
It's weird...that one works and the other doesn't.
Thanks..
Cheska
[mx]variable, Text, Target Problem
hello,
this will be very simple but i just cant figure it out.
on _root i have a dynamic text field, variable name "mytext".
on _root i have a global variable called "whatText".
on _root i have a movie clip named(scrollMov) that should scroll "mytext".
'scrollMov' uses the variable 'whatText' to build up a target path to textfield its supposed to scroll, as below;
PHP Code:
path = "_root."+whatText;trace(path);path.scroll--;obviously this aint php, but there is no as button!:smirk:
this outputs the correct path but will not scroll the text. if i hardcode the path it works fine.
what am i doing wrong to target the text?
Applying A Variable Function To A Series Of Buttons
I've been coding for about six months, and somehow I've still never managed to solve this one basic issue. How do I write a single function to manage a series of buttons? If I create a series of buttons, my inclination is to do the following:
1. Put the button series into an array
2. Create a loop to cycle through the array and apply a function to each button that varies based on "i" within the loop.
Now I realize the problem with what I am doing. By the time I click a button, the loop has cycled all the way through and applied the final "i" value to every button.
But, I cannot figure out how to get around this. I'm sure it is a simple fix, and I equally sure that it has been addressed a thousand times in this forum, but I've looked for weeks, and still haven't found an answer. How do I deal with applying a variable function to a series of buttons?
I will include a simple example below that follows the basic problem that I find myself if. How would someone do this differently?
EXAMPLE:
var button_array:Array = new Array(button1_btn, button2_bth, button3_btn, button4_btn);
for (var i:Number = 0; i < button_array.length; i++) {
button_array[i].onRelease = function() {
trace(i+1);
}
}
How do I trace i such that if I click button1_btn, I get "1" and if I click button3_btn, I get "3" (and so on)?
Thanks for baring with a basic question,
tophers
Stuck In For Loop When Using Variable From Text File
Hi,
I have a very simple for loop in my flash file:
for(i=1; i<=counter; i++){
trace("blah");
}
And for some reason, when I try to use a value for counter that I have gotten from a text file, it just gets stuck in an infinite loop. For example, if I have a variable in the text file like numOfLoops or something, and in the text file, say I set it to like, 3... Well, then if, in the loop, I do:
for(i=1; i<=numOfLoops; i++){
trace("blah");
}
Then it gets stuck in an infinite loop... And the weirdest part is, if I do
trace(numOfLoops);
...then it does trace the correct value, it outputs 3 (or whatever I initialized it to in the text file).
Another weird thing is that I even tried this:
var counter = numOfLoops;
...and then I tried going through the loop with the counter variable, but it still didn't work.
Does anyone know what the problem may be?
Thanks,
Heather
Loading Text In A For Loop...variable Problem?
Hi I am having a problem with the following script. I am using flash mx 2004 proffesional. This may be a simple problem I am fairly new to actionscript.
Ok so i want to import some text from an external text file (called titleText.txt). Within this file I have a variable called t1. I want to import more text from this file under different variables t2 t3 t4 etc... To do this i was going to put the following script in a for loop eg- for(i=0;i<5;i++) etc
To facilitate this i have created the line
titleVar= "t"+i;
and have called this in the following script instead of directly calling the variable. However it doesn't work! I am pretty sure the script is right in so far as loading in text because if i just stick with the variable name (t1) it works fine. Any suggestions on where I am going wrong?!
loadVarsText = new LoadVars();
loadVarsText.load("titleText.txt");
titleVar = "t"+i;
trace(titleVar);
loadVarsText.onLoad = function() {
reel_mc.titleText2_txt.text = this.titleVar;
};
titleText2_txt.text = loadVarsText.titleVar;
Thanks
Dividing Number X (30, 25, 13, Etc..) Amongst Text Fields (1-100 Fields)
Sorry about the title of this post, but I didn't find it easy to make a descriptive title.
What I'm trying to do, isn't a huge project, and I don't believe it's infinitely complicated. I just can't seem to wrap my head around it at the moment.
Hard enough to explain what I want...
Try to picture this:
Flash file opens up.
There are 6 text fields on the screen.
You enter the number 30 into a text field located near the top and press a button.
The 5 remaining text fields suddenly have numbers in them:Field 1: 30
Field 2:8
Field 3:9
Field 4:3
Field 5:5
Field 6:5
The idea is that I need a piece of code that will divide a variable amount of 'points' between a variable number of text fields. But not only does it have to be divided it has to be randomly and often unevenly divided.
So X = Number of text fields X / 30
Won't bring about the desired results.
I think I can (but haven't tried) divide 30 evenly easy enough, but since thats not what I'm after...
Any suggestions?
Seems to me that the final code will be one of those 'Wonder why I didn't see that' sort of things. But I can't get it.
Thanks for your help.
-Lem
Putting Text On Series Of Duplicated Movieclips
Hi all!
I want to set/change a dynamic text field in duplicated movieclips. The dynamic text field is nested in the moviclip.
For the original MC this code works fine:
code: _root.lookTarget_mc.targText.text= "pizza";
('lookTarget_mc' is the movieclip instance and both the instance and the variable of the dymanic textfield is 'targText'.
So how do I do it with a duplicated movie clip?
The duplication code is:
code:
duplicateMovieClip("lookTarget_mc", "new"+i, i);
I tried various things like
code:
_root.new99.targText.text= "pizza";
_level0.new99.targText.text= "pizza";
But it always come up with something like 'level0.new99.targText' in the text field.
Maybe I'm putting the code in the wrong spot (it's in an action layer in the general timeline).
Write For Loop To Insert Value In2 Multiple Fields
hi, i'm using flash mx.
i've got four mcs, each of them got an answer field in it. how do i write a for loop that appends their values frm an array inside e field?
this is wat i've tried, of cuz it doesn't work.
for(k = 0; k<4; k++) {
("button"+k+1+".answer.text") = ansArr[k];
}
How Can I Target This MovieClip That I Loaded Onto The Stage?
I'm trying to target a .swf that I loaded into a movie clip (mc_container) but it seems like I'm missing something. Can you take a look and see where I went wrong?
Code:
mc_container.loadMovie("mc_photoSwap.swf");
//homepage Animation Swap Images
function photoSwapAni(){
switch(random(3)){
case 0:
_root.mc_container.gotoAndPlay("ani_1");
trace("case 0");
break;
case 1:
_root.mc_container.gotoAndStop(50);
trace("case 1");
break;
case 2:
_root.mc_container.gotoAndStop(100);
trace("case 2");
break;
}
}
var intervalID:Number = setInterval(photoSwapAni, 2000);
Also I see I'm going to have an issue with the random part because it could call the same animation twice or more times in a row. Should I ad some sort of if statement or is there a better way to do this random part of the code?
[F8] How Can I Target This MovieClip That I Loaded Onto The Stage?
I'm trying to target a .swf that I loaded into a movie clip (mc_container) but it seems like I'm missing something. Can you take a look and see where I went wrong?
Code:
mc_container.loadMovie("mc_photoSwap.swf");
//homepage Animation Swap Images
function photoSwapAni(){
switch(random(3)){
case 0:
_root.mc_container.gotoAndPlay("ani_1");
trace("case 0");
break;
case 1:
_root.mc_container.gotoAndStop(50);
trace("case 1");
break;
case 2:
_root.mc_container.gotoAndStop(100);
trace("case 2");
break;
}
}
var intervalID:Number = setInterval(photoSwapAni, 2000);
Also I see I'm going to have an issue with the random part because it could call the same animation twice or more times in a row. Should I ad some sort of if statement or is there a better way to do this random part of the code?
Drop Target Using Loop
I am working on a puzzle where there are two boxes
The left box is empty and contains 16 blank movieclips with property name:
c1, c2, c3 etc. till c16 and in the right box there are jumbled movieclips with names:
p1, p2, p3 etc. till p16.
Now I am using drop target so that if "c1" matches "p1" it will automatically snatch the image and "c2" will snatch "p2" and so on.
Here is the code that I am using for the first movieclip:
Code:
p1.onPress = function()
{
p1.startDrag();
};
p1.onRelease = function()
{
if(p1._droptarget=="/c1")
{
// align p1
p1._x = c1._x + (c1._width-p1._width)/2;
p1._y = c1._y + (c1._height-p1._height)/2;
};
p1.stopDrag();
};
And now I want to do this thing for rest of the movieclips and I want to do this using for loop and here is the code which is not working:
Code:
for(a=1; a<=16; a++)
{
_root["p"+a].onPress = function()
{
this.startDrag()
};
_root["p"+a].onRelease = function()
{
if(_root["p"+a]._droptarget=="/c"+a)
{
// align p1
_root["p"+a]._x = _root["c"+a]._x + (_root["c"+a]._width-_root["p"+a]._width)/2;
_root["p"+a]._y = _root["c"+a]._y + (_root["c"+a]._height-_root["p"+a]._height)/2;
};
this.stopDrag();
};
}
Can anyone figure it out what mistake I am making?
Thanks in advance
Target An Instance From A Loop
If you have a loop that produces multiple instances of a class (such as in the code below), how do you target these instances when
1. you dont know there name
2. you don't know there index
3. you DO know who their parent is
from outside of the loop?
ActionScript Code:
for (var i:Number=0; i < 4; i++) {
var movementBtn:GenWorkBtn=new GenWorkBtn;
movementBtn.name=passedName + i + "_btn";
_mainTL.menuCont.addChild(movementBtn);
private function outClick(event:MouseEvent):void {
//target instances here
}
Target Button In A Loop
I have the below code which attaches a movieclip "btn1" to another movie clip within this loop I wish to setup up different functions for each different button but it only lets me set them up for the last one in the line of buttons. How to I target each button seperatly by using a string and then the value of miniLoop? i.e
subnav.test_mc.item1
subnav.test_mc.item2
code--------------------------------
for (var miniLoop=0; miniLoop < imageLength.length; miniLoop++) {
var currentImage = imageLength[miniLoop];
var item_mc = subnav.test_mc.attachMovie("btn1","item"+miniLoop, miniLoop);
item_mc.onRollOver = function() {
trace("test");
}
item_mc.onPress = function() {
image_mc.loadMovie(this.url);
trace(miniLoop);
trace(desc[0]);
}
item_mc.url = currentImage.attributes.url;
item_mc._x = miniLoop * subnav_spacing ;
}
Button On Main Stage Target Frame In Mc
This seems simple, but for some reason it is not working.
I have a button on the main stage. I want to target my MC (McSlidey01) that is placed on the main stage.
facts:
McSlidey01 is a MC that is 50 frames long. On the last frame it has an action script that takes it back to the root and advances to the nextFrame.
button01 is on the main stage. I want this button to stop McSlidey01 on frame 25. This way it will stop the MC and not advance to its last frame that has the nextFrame action on it.
Load Library Clip Into Target On Stage
Hi. Wouldn't bother anyone with this but have been at it for hours and am at max frustration level. I'm using Flash CS3. I want to rollOver a button on the stage which will load a movie clip from my library into a movie clip that is currently sitting on the stage.
The desired effect would be comperable to using the loadmovie command and loading an external .swf into a target on the stage. Except in my case I want to load a clip located in my library into the target, instead of having to load an external swf file. Make sense? The objective of doing it this way is I want the loaded clip to sit there on the stage while the cursor mills about. But when the cursor rolls over another button, I would like a different clip in the library to replace the one previously loaded by the first button.
Any suggestions would be greatly appreciated. Please be specific as I tend to get lost easily with this stuff. Thank you in advance.
How To Target The Method Of An Object Added To The Stage?
Hi everyone,
I have 2 classes, a ColorSample class and a tile class.
Basically what I want to do is to change the color of a tile on the stage by clicking on a colorSample object
My problem is that from the ColorSample object, I can't access the changeColor method of a tile object from Tile class that I have instantiated and added to the display list.
I have a : ReferenceError: Error #1065: Variable tile_mc is not defined when I try to call that function defines in the ColorSample class
and when I defines the var tile_mc:MovieClip; in the ColorSample class it throws me:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I've been banging my head on the wall all afternoon, can somebody help me?
Thanks guys!
Mailing Variable Fields
i have a problem in that i need to send the contents of a variable field to my mail agent.
the crunch is that the feild in question (with the variable set as "email") is contained within an mc, and needs to pull it's content from another field (also named email) which is on the parent timeline and on a previious scene.
Now, i can't prefix the variable with; "_root" or" _parent" the variable must be set as "email" for the mail system to work.
i thought there may be some script i could use to pass the content from one box to the other.
Variable, Multiple Fields
So far I am able to bring up variables from a .txt file, make them appear in text fields, use buttons to display visually 2 choices from 2 buttons ".mp3", or ".wav". However, when I add a third button and make a new field for the choice to appear I just get "_level0.extension" and not the value of the variable EXTENSION
What am I doing wrong?
In the file mp3 and wav buttons are noted, result will appear above center from the buttons. The other field and button is what I am trying to get to display the EXTENSION value.
Grassy Fields - Variable RXN
onClipEvent (enterFrame) {
x = (_root._xmouse+5)/rxn;
this._xscale = -x;
this._x -= x/50;
pos = this._x;
if (pos<-50) {
this._x += Math.round(550+Math.random()*100);
}
}
Can someone please explain the line:
x = (_root._xmouse+5)/rxn;
what is RXN?
Thanks
Sam.
Grassy Fields - Variable RXN
onClipEvent (enterFrame) {
x = (_root._xmouse+5)/rxn;
this._xscale = -x;
this._x -= x/50;
pos = this._x;
if (pos<-50) {
this._x += Math.round(550+Math.random()*100);
}
}
Can someone please explain the line:
x = (_root._xmouse+5)/rxn;
what is RXN?
Thanks
Sam.
BitmapData.draw(target, New Matrix()) And On-stage Transformations
see attached file:
I'm trying to transform a MC on stage and use the BitmapData filter on it. But apparently you must pass a matrix for it to hold the on-stage transformation
Quote:
Originally Posted by livedocs
A source MovieClip object does not use any of its on-stage transformations for this call. It is treated as it exists in the library or file, with no matrix transform, no color transform, and no blend mode. If you want to draw the movie clip by using its own transform properties, you can use its Transform object to pass the various transformation properties.
Any ideas why this isn't coming out correctly?
see file or replicate:
ActionScript Code:
//
import flash.display.*;
var dup:MovieClip = _root.createEmptyMovieClip("dup", 0);
dup._y = box._y;
dup._x = box._x + box._width + 10;
var bmp:BitmapData = new BitmapData(box._width, box._height, false, 0x996633);
bmp.draw(box, box.transform.matrix);
dup.attachBitmap(bmp, 0);
//
Cheers.
How To Use GotoAndPlay() In Actionscript File To Target Object On Stage?
Good day!
Im new to actionscript 3, and id like to know how to use gotoAndPlay to target an object (drawn from hand to stage) on the stage using actionscript file?
My code is this:
Code:
package
{
import flash.display.MovieClip;
public class moveframe extends MovieClip
{
public function moveframe()
{
parent.getChildByName("stick").gotoAndPlay(2);
}
}
}
It will only generate an error message saying: "Call to possibly undefined method gotoAndPlay through a reference with static type flash.displayisplayObject.
parent.getChildByName("stick").gotoAndPlay(2);"
I dont know what this error message means, but does anyone knows what the problem is?
I tried to trace the X position of the child named "stick" using: traced(parent.getChildByname("stick").x); to make sure that the object is already existed, but it produce the X position of my "stick" object which means that it is present. but when i try to use gotoAndPlay(2) it will make an error.
does anyone knows any alternative way to refference the movieclip object that has been put to stage?
thank you..
Loading Images Into Target On The Main Stage From A Clip
Hi,
I have an infinite menu displaying thumbnails of some larger images I would like to display on my main stage in a target destination but, for some reason, I cant get the images to load up.
I have followed the following steps:
1. created a hotspots over each thumb in the infinite menu
2. labeled each instance of the hotspot (eg. but1)
3. attached the following code in the timeline:
but1.onPress = function() {
_root.createEmptyMovieClip("container", 1);
loadMovie("http://www.myurl.com/images/image1.jpg", "container");
container._x = 240;
container._y = 27;
};
If anyone can offer some advice I would greatly appreciate it.
Thank you kindly.
Michael
Loader: Target MovieClip On Stage(_root?) From Loaded Swf
Hi,
I know there's a lot of posts on this subject but I've been pulling my hair out and still can't find a solution. It's killing me. It seems like it should be so simple. I've got a site where i load in various swf files from my main file(main.swf) that contains the nav. Here is the function that's called when the swf is loaded in:
function loadComplete(event:Event):void {
trace("Complete");
stage.addChildAt(loader, 0);
holderMC = event.target.content;
holderMC.gotoAndPlay(2);//this sends the loaded swf to frame 2 where some buttons exist
}
the problem i can't figure out and can't find a clear explaination to is this:
how do i target a movieclip on the main timeline(instance name 'animationstuff') of the loader swf(main.swf) from a button in the loaded swf? the movieclip in the main timeline was placed on the timeline manually and not through actionscript.
i've tried tons of different methods and none have worked so i'm hoping someone can explain it. this new display list has me so confused.
How To Use GotoAndPlay() In Actionscript File To Target Object On Stage?
Good day!
Im new to actionscript 3, and id like to know how to use gotoAndPlay to target an object (drawn from hand to stage) on the stage using actionscript file?
My code is this:
Code:
package
{
import flash.display.MovieClip;
public class moveframe extends MovieClip
{
public function moveframe()
{
parent.getChildByName("stick").gotoAndPlay(2);
}
}
}
It will only generate an error message saying: "Call to possibly undefined method gotoAndPlay through a reference with static type flash.displayisplayObject.
parent.getChildByName("stick").gotoAndPlay(2);"
I dont know what this error message means, but does anyone knows what the problem is?
I tried to trace the X position of the child named "stick" using: traced(parent.getChildByname("stick").x); to make sure that the object is already existed, but it produce the X position of my "stick" object which means that it is present. but when i try to use gotoAndPlay(2) it will make an error.
does anyone knows any alternative way to refference the movieclip object that has been put to stage?
thank you..
Loading Images Into Target On The Main Stage From A Clip
Hi,
I have an infinite menu displaying thumbnails of some larger images I would like to display on my main stage in a target destination but, for some reason, I cant get the images to load up.
I have followed the following steps:
1. created a hotspots over each thumb in the infinite menu
2. labeled each instance of the hotspot (eg. but1)
3. attached the following code in the timeline:
but1.onPress = function() {
_root.createEmptyMovieClip("container", 1);
loadMovie("http://www.myurl.com/images/image1.jpg", "container");
container._x = 240;
container._y = 27;
};
If anyone can offer some advice I would greatly appreciate it.
Thank you kindly.
Michael
How To Target Dynamic TextField Objects From Within A Loop
I have a loop that generates a bunch of 5 (from an array) dynamic TextField objects using the createTextField() Method.
for(var i:Number=0; i<languages.length; i++) {
_root.createTextField("language_"+i,_root.getNextH ighestDepth(),xpos[i],ypos[i],200,200);
}
I want to know how I can target these textfields one by one to add the correct text to them from within my loop. I can't figure out how to actually talk to each TextField object by dynamically calling the TextField name. I know I can do it using static code outside the loop as easy as pie, but I want to do it here! THis is a problem I ften run in to.
Thanks.
Gareth
How Do I Target These Attached Movie Clips In For Loop
i want to when i click a button delete all these 50 smoke movie clips from the movie... how?
unloadMovie(_root.smoke_mc+j")????
_root.smoke_int = setInterval(createSmoke, 50);
function createSmoke() {
for (j=0; j<50; j++) {
var newSmoke = attachMovie("smoke", "smoke_mc", 500+j, {_x:400, _y:400});
newSmoke._x = (random(5)+70);
newSmoke._y = (random(100)+185);
newSmoke._xscale = (random(20)+50);
newSmoke._yscale = (random(120)+50);
newSmoke._alpha = random(5);
newSmoke.gotoAndPlay(random(20)+1);
}
}
How To Keep Hold On The Target When Loading With Loader Loop
So i have to load 20 images with a loop that goes through a loader function and resize them:
Code:
for(var k:uint=0; k<_albumObjects.length;k++){
imageLoaderFuntion(MEDIA_ROOT+_albumObjects[k].cover, _albumsArray[k]);
}
and the loader function looks like that:
Code:
private function imageLoaderFuntion(url:String, target:MovieClip):void{
if (imageLoader != null)
imageLoader.close()
var imageLoader:Loader = new Loader();
configureListeners(imageLoader.contentLoaderInfo);
var image:URLRequest = new URLRequest(url);
imageLoader.load(image);
target.addChild (imageLoader);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.INIT, function(e:Event):void{
rearrange(); // THE PROBLEM
});
}
Now, the whole problem is that i want to resize/rearrange those pictures and i dont have access to them and i dont have reference to the 'just loaded' picture. So basically i want to be able to resize pic x right after it is loaded. and also i want to do other things when all pictures are loaded. All i have for the moment is this:
Code:
dispatcher.addEventListener(Event.INIT, function(e:Event):void{
rearrange();
});
which is a function that can be executed after something (we don't even know what!) is executed. How do i store variable of the 'target' or ... any smarter way to do it?
i can rephrase if not clear...
Adding Movieclips With Addchild And A Loop...how To Target A Specific One?
I have this code:
----------------------------------------------------
for(var i:Number = 0; i < 10; i++) {
buttonVar = new button();
addChild(buttonVar);
buttonVar.x = i*120;
}
----------------------------------------------------
It creates a 10 movieclips and moves them apart 120 units, what I want is to target a specific created movie clip. Say for example the number 4 in the loop, how can I asign a specific instance to that movieclip? to differentiatte it from the other ones ? any idea ?
Loop Through All Objects On Stage?
Is it possible to loop through all of the objects on the stage of a movie?
Say I have a movieclip that I placed 10 TextFields and 2 Combobox Controls on (not dynamically, at design time).
How would I loop through all of the objects?
I have tried the
ActionScript Code:
for (var obj in this)
{
trace(this[obj]);
}
but that does not trace anything, like it isnt getting into the for loop at all.
How Do You Target A Variable?/
Lets say I've set a variable....how would I go about targeting it? If I want to command the variable to do something........do I use tell target, or the call action? I'm a bit confused on this...perhaps someone could straighten me out. Thanks.
Variable To Tell Target (please)
Hej guys and gals. this is any another easy one I hope.
I am wondering how you send a movie clip to a specified frame number...when that frame number is containted within a variable which is set by the preceeding frame. I can see you can use tell target to send the specified clip to a number, a label, or an expression.- but i can't make it work because I don't have a number as such..the number is the variable if that makes sense....er...a little background for you.
Here is bascically what i am doing. The following descibes the contents of an MC, we'll call it "ControlClip" which is designed itself to control another MC, in this example, one called "MyMovieClip"
Frame 1 of "ControlClip"
--------------
var MyVariable = 3
Frame 2 of "ControlClip"
--------------
tellTarget ("_root.MyMovieClip") {
gotoAndStop (MyVariable);
}
Stop();
Now, this doesn't work. I am looking for some help with the syntax..assuming this is even possible.
many thanks.
david
|