[help]dynamic Instance Name Method
Hi,
I have this problem that seems easy but can't solve. I need to reference dynamic instance names, wich works fine whe getting/setting properties, but doesn't work when trying to use methods. Like: code: eme="popo"+1; ele="popo"+2; trace(eme.getDepth()+" "+popo1.getDepth());
would output="undefined -16383"
I don't know the correct syntax for this, and i want the instance name to be a variable, to go on changing it and be able to send properties and action to duplicates of a movie clip.
Any help would be appreciated...
Salut!
FlashKit > Flash Help > Flash General Help
Posted on: 11-08-2005, 02:40 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
String Method From Instance Name
I'm having trouble with this(to make it quicker I'll just write here the necessary info):
I have a variable called currentURL.
this variable containes the instance name of a movieclip(in this case it's home).
I want to write a string with the instance name WITHOUT THE INITIAL _LEVEL0 PATH ELEMENT.
As I try to make a string from the variable with:
currentURLstring = new String(currentURL);
The string returnes:
_level0.home
I then try to slice it in many ways, let's say with substr:
currentURLstring.substr(7);
In theory the function showld produce a string like this:
home
...instead I still get the full path....
WHY?!?!?!?!?!?!
where am I mistaking?
here is the code:
// home is the instance name for a movieclip.
currentURL = home;
currentURLstring = new String(currentURL);
currentURLstring.substr(7);
StatusUpdate(currentURLstring);
How To Get The Class Instance Of A Method
Hi guys,
My first post on kirupa.
Is there a way to get the class instance
(meaning "aMenuInstance" inside SomeClass) from the passed method "load"
_scope inside Task should be the "aMenuInstance" from SomeClass.
Code:
public class Task extends EventDispatcher
{
private var _scope:Object;
private var _method:Function;
private var _evt:String;
public function Task(method:Function, evt:String = "")
{
// _scope would need to be _aMenuInstance
_scope = method.some_magical_undocumented_function_or_something;
_method = method;
_evt = evt;
}
.....
}
Code:
public class SomeClass
{
private var _aMenuInstance:SomeMenuClass;
public function SomeClass ()
{
_aMenuInstance = new SomeMenuClass();
var aTask:Task = new Task(_aMenuInstance.load, "menuLoaded");
}
}
any ideas?
Compare An Instance To Itself In Its Own Method?
How can I compare an instance, in this case in an array (eg myInstances[3]) to check whether it is itself in its own method.
Example (This is what I've been trying that hasnt been working):
Parent
Code:
myArray[i] = new Class;
...
myArray[j].checkSelf( myArray[i] );
Class
Code:
function checkSelf( a_instance ) : Boolean
{
if( a_instance == this ) return true;
}
Heeeeeeeeeeeeeeeeeeeeeeeeeeeeeelp
Release Instance Of Class With Method
hello everyone
i have problem with release instance of class with method
Code:
function myClass(){};
myClass.prototype.method = function(){
trace("method");
}
var myInstance = new myClass();
myInstance.method();// method
delete myInstance;
myInstance.metod(); //
the instance has released above
Code:
function myClass(){};
myClass.prototype.method = function(){
trace("method");
}
myClass.prototype.release = function(){
delete this;
}
var myInstance = new myClass();
myInstance.method();// method
myInstance.release();
myInstance.metod();// method
the instance has not released if i use "release" method??
how can i use method delete self of instance??
Issues W/ Using Draw Method For BitmapData Instance
I'm just wondering if there are known issues with using the "draw" method of the BitmapData class...in my case, I'm loading in a SWF and converting it to a bitmap using the "draw" method and for some reason, it's drawing a different SWF than the one it's supposed to. It's like it is getting the SWF's confused and drawing the wrong ones to the wrong places?
has anyone ever had a problem with this? I don't think it's my logic, but it's always possible! My logic is working the way I think it should w/ this exception???
thx for the replies...here's an excerpt of my code:
Code:
//this code takes the loaded SWF (swfArray[i].content) and makes it into a Bitmap, then places the Bitmap into an empty
//movie clip (bitmapContainer) that has name and type values to record SWF name and type(category/class)//////////////////////////////////////////////////////////////////////////////////////////////////////
for(var i:int = 0; i < swfArray.length; i++) {
var swf:DisplayObject = swfArray[i].content;
var bd:BitmapData = new BitmapData(swf.width, swf.height); //scale down here if you want.
bd.draw(swf); //if you're scaling down, the optional second arg is a Matrix.
var swfPic:Bitmap = new Bitmap(bd);
swfPic.x = swfPic.y = 0;
swfPic.name = "swfPic";
var bitmapContainer:BitmapContainer = new BitmapContainer();
bitmapContainer.addChild(swfPic);
bitmapContainer.type = type;
bitmapContainer.swfName = swfNames[i];
bitmapContainer.positionInQueue = i;
bitmapContainerArray.push(bitmapContainer);
}
NOTE: this excerpt is contained in a loop, so it's performed multiple times if that helps clarify any issues!
Problem Setting Instance Variables Within Method Called By SetInterval()
Anyone know how to set variables of an object instance from within a setInterval() function which is, itself, a method of the object?
To explain, here's the prob simplified...
Say I have an instance of an object called myObj which has a property called myObj.numThings I have an onRelease() event handler defined for an mc attached to myObj which triggers a setInterval() call. This code sits in an initialisation method for the class. The code looks something like:-
Code:
this.mySubClip.onRelease = function () {
// initialize our property (nb. we are in scope of event handler's clip now
// so use 'this._parent' to refer to main object
this._parent.numThings = 0
// call our setInterval method
this._parent.intervalID = setInterval(this._parent,
"startInterval", 100, numThings, this._parent);
}
The setInterval() method of myObj looks like this in the class def:-
Code:
// method used for interval invocations
// n.b we pass a ref to the calling clip to the method so it can easily
// clear the interval when we need it to
MyObj.prototype.startInterval = function(thingsCnt,callerRef){
trace("Value of our object property is: " + thingsCnt);
if(thingsCnt > 10) {
trace("We're done");
callerRef.clearInterval(callerRef.intervalID);
} else {
thingsCnt++; // I want this to modify my object property (myObj.numThings)
}
}
The problem is, I can't get the setInterval method "startInterval" to modify the objects property "myObj.numThings". The interval keeps executing and the value of thingsCnt remains the same. If I use a filepath to "numThings" in the setInterval() invocation (i.e "this._parent.numThings") a null value is passed to startInterval().
This is a subtle one but I know it's got soemthing to do with scope.
Hope someone can help
Dynamic Instance Name Vs Manual Instance Name?
Hello,
I would like to access this object (taken from Debug > List Objects of in flash player)
ActionScript Code:
Target="_level0.promotion0.loader_mc.instance87.promo TXT"
This is what I am trying to access it with:
ActionScript Code:
trace( this.getChildByName("promotion0").loader_mc.getChildByName("instance87").promoTXT.text );
Error:
ActionScript Code:
1119: Access of possibly undefined property loader_mc through a reference with static type flash.displayisplayObject.
what is the correct way to do this?
Delete Instance Of Class From Class' Method
So I have a class called Unit. When I use this class in a .fla file, I create it by saying:
var unit00:Unit = new Unit(...);
So then it creates a gfx representation of the screen for me. I would like to have a method like this:
PHP Code:
public function remove ():Void { unit_mc.removeMovieClip(); //deleting the gfx representation of the class in the .fla delete instance of this; //I want to delete the variable that references the instance of this class}
So how do I get this to work? I know that delete this will not work when defined inside the class. How do I target the .fla's instance name when I don't know what it will be called?
Thanks for any assistance
Instance Names...changing...or Addressing Txt Field Instance Based On Instance Of Mc
i'm creating a mail form, that has a text effect which displays the type of info to be entered in each input box. To create this effect, i had to assign the variable name txt to the input boxes as well as the instance name txtBox. each of these text fields is contained within a movieclip, each with a unique instance name. what i need to do, is somehow assign a value/variable to each text field to pass to PHP to generate an email. I have always used components for contact forms so i'm not sure how to make the switch, AND.. the script i use for my contact form is an EXTERNAL AS file. (i use a customized version of a contact form from www.actionscript-toolbox.com [which apparently is no longer Flash related site])
ok.. this is hard to explain..... so bear with me....
If my original mail form component instance names were: tiName, tiEmail, tiSubject and taMsg (ti for textInput and ta for textArea)
and my current instance names for the mc's which CONTAIN the input boxes (with txtBox textfield instance inside them) are: name_txt, email_txt, subject_txt & comments_txt...
how would i pass/convert the users input text in each movieclip's txtBox, into the original instance name for my mail form so i can continue to use the form/PHP i have been using??
OR....
how do i take the values input by the user in each txtBox (i.e name_txt.txtBox.insertedTextFromUser or name_txt.txt, email_txt.txtBox.insertedTextFromUser or email_txt.txt) and send them to a new PHP script to send mail??
please keep in mind i am PHP retarded... hence why i re-use the same form over and over..
thanks in advance for any help. it's greatly appreciated...
if you're confused about my problem, please let me know... i'm having a difficult time explaining....
Method Call On Dynamic CreateEmptyMovieClip( )
Trying to call the play() method on dynamically created instances of Movie Clips:
mediasLoaderListener.onLoadInit = function(target_mc:MovieClip) {
target_mc.stop(); //Stop() is working on initialisation of the movies
}
function populateMediasSlot(){
for(i=0; i<lengthArray; i++){
var mediaName:String = this.defautBoucle_array[i]+".swf";
this.createEmptyMovieClip("medias_slot_"+i, this.getNextHighestDepth());
var mediasLoader:MovieClipLoader = new MovieClipLoader();
mediasLoader.addListener(mediasLoaderListener);
mediasLoader.loadClip(mediaName, this["medias_slot_"+i]);
}
}
Example :
this.medias_slot_0._x = 0; //Call on properties works
this.medias_slot_0.play(); //Call on play() won't work once out of the initialisation listener.
AS3 Dynamic Symbol Instantiation - Best Method?
Hi
I've just migrated to AS3 and am trying to get my head around how to instantiate library symbols as instances of a class.
Here's the problem: I'm making a tile-based game with a Map object to which are linked many Tile objects. Now while I initially create blank tiles, I later want to populate them with terrain. This operation will change thus the tile's _terrainType property. Finally, I want to then draw the map consisting of its many tiles. Tiles without a terrain type will remain plain vanilla, but those that have terrain types specified would obviously appear different.
Now the Tile object itself extends Sprite, so it is a DisplayObjectContainer (k, no problems there). My question is, how do I now either a) directly assign it a library symbol graphic, following it's instantiation (if this is even possible?) or b) dynamically use addChild() to add a library symbol graphic of a certain classname (my preferred tactic)?
The problem is if I have to do something like this...
Code:
var tileImg:MovieClip = new mountainTerrain();
addChild(tileImg);
...then I have to write a bleedin' huge switch() statement to reference a hash table which specifies which terrain type refers to which symbol class type, which is just ugly and crap.
The most logical thing to me would seem to be something like this...
Code:
var tileImg:MovieClip = new eval(classname)();
addChild(tileImg);
...but clearly I'm misguided because eval() doesn't even exist in AS3 and I have attempted it's equivalent with no likelihood of success.
Can someone help me here? How do I dynamically add a graphic to represent each instance of my Tile class? Am I approaching this the wrong way altogether, or do I just not have the correct keywords handy?
-Nick
SwfObject Dynamic Publishing Method
According to the documentation for swfObject, this is supposed to happen:
Quote:
It avoids click-to-activate mechanisms to activate active content in Internet Explorer 6/7 and Opera 9+.
Why am I still getting the click-to-activate activeX warning in IE7?
Calling A Method On A Dynamic Class (Reflection)
ActionScript Code:
var cn:String = 'com.me.Baloons';
var DynamicClass:Class = flash.utils.getDefinitionByName(cn) as Class;
var item:UIComponent = new DynamicClass();
Now cn is TOTALLY dynamic. I would like it to call it's method 'showName()'. How do I do it?
ActionScript Code:
item.showName()
<-- fails
Effective Method To Load Dynamic Content In To Flash?
I have to create some 30 to 40 pages of content in flash. The content has text, graphics, animations, interactivities like drag and drop, MCQ's etc. Data should come from outside flash say an xml file. Can any one suggest an effective way to do this. Thanks.
Best Method For XML Content, Multiple Comboboxes, Populating Dynamic Text
Hi folks,
Im looking for some input on the following project. In principle I have a good idea of what shold happen, but its the implementation i'm unsure of.
Basically I built a CDROM in Flash with a bunch of podcasts on it for an event. It went down really well and now they want to release a regular version. In order to manage the regular updates in an efficient manner, i'd like to set up the content externally using XML and do the wizardry with AS3.
The scenario is this, at the moment there are 6 business units but as this gets bigger more will be added (up to 10). Every business unit has its own podcasts, of varying numbers. The podcast CD is 2 screens - an introduction and the podcasts lists(buttons), and a second screen with the flv/mp3 player and the podcast details.
So in principle i need to do is load in the XML, and for every business unit, add a combo box to screen 1, underneath the last one, and populate it with the names of the podcast. When a podcast is selected from the drop down i need to transition to screen 2, populate the dynamic text fields with the specific podcasts details and play the movie.
The guts of the XML will look something like this i guess:
Code:
<businessunit id="">
<podcast>
<path></path>
<title></title>
<overview></overview>
<cta></cta>
</podcast>
<podcast>..........
</podcast>
</businessunit>
<businessunit id="">
<podcast>..........
</podcast>
</businessunit>
The real question for me is, what is the best way of populating multiple comboboxes and how do i track/populate the second screen from the selection on screen 1. I don't really want to ID every podcast so using their position in the XML structure would be a better means of ID for me? There are a few potential options I see for handling the XML - reading all the data into arrays, but seems a bit antequated; using the new E4X syntax; and there's potentially XMLLIST?!
So really not sure what to do for best here - any help or examples much appreciated!!!
Custom Remoting Servie Class Using Dynamic Cfc Method Names
I'm new to actionscript and I'm trying to write a custom remoting service class that recieves parameters for the service and pendingcall methods (gateway string, function name, etc. - to be used with a coldfusion component)
My problem is this:
Is there a way to receive a function name as a variable and then execute it using the variable name? In the code below, the cfc method "get_message_cfc_meth" is hardcoded but I want to be able to pass in a variable and execute whatever function name gets passed in.
class Access_cfcFunction {
function makeThisConnection(thisGateway:String){
var thisConnection:Service = new Service(
thisGateway,
null, //log info
"jeffCFCtest.helloWorld2",
null,
null);
var pc:PendingCall = thisConnection.get_message_cfc_meth();
pc.responder = new RelayResponder( this, "get_message_cfc_meth_Result",
"get_message_cfc_meth_Fault" );
pc.onResult = function (result){
_root.messageDisplay.text = result;
}
}
}
Thank you!
What Is The Instance Name :: Dynamic
I am trying to set a variable inside an MC equal to the instance name of that MC. So, if I have a MC called MCmyTest and I give it an instance name of test1. How can I get the variable inside MCmyTest named "whatAmI" to be assigned the value of the instance of this movie clip (test1).
inside of the MCmyTest with an instance name of test1:
code:
whatAmI= //this is where I need to know the syntax that would put the instance name here so it will equal "test1"
I am guessing it would involve this._parent or some crazy combo like that.
Thanks for your help.
Dynamic Instance Name
When creating textfields via the createTextField within a for next loop i.e
test.createTextField("textBox"+cnt,cnt,10,spacer,1 00,20);
If i then wanted to assign text to "textBox"+cnt how would I do this?
I know that [_root.test.textBox+cnt.text = "text box number"+cnt;] won't work? how do I make reference to the newly created text box?
Thanks in advance for any help..
Dynamic Instance Name
Hey all,
Im not quite sure how I would go about setting a dynamic instance name of each of my RadioButtons, my code below has 3 radio buttons which are 50 px apart from each other, however these radio buttons will all have the same instance name (RBtn_1)
I would like the radio buttons to each have a unique instance name, e.g. radio button 1 has a instance name of RBtn_1, radio button 2 has a instance name of RBtn_2 and so on
I've been looking around and I only seem to be finding replys which are in AS2 or are not quite what Im looking to do.
Thanks in advanced!
alex
ActionScript Code:
import fl.controls.*;
var distance:uint = 100;
for(var i:int=0; i<3; i++) {
distance = distance + 50;
var RBtn_1:RadioButton = new RadioButton();
RBtn_1.label = String(i+1);
RBtn_1.x = distance;
addChild(RBtn_1);
}
Dynamic Instance Name
Hi Guys,
Right, i'm having a problem getting a dynamic name to work. all the way through my script i have been using:
ActionScript Code:
this["c"+questionNumber+"_mc"]
so c1_mc for example, is the name of a movieclip, so i can say:
ActionScript Code:
this["c"+questionNumber+"_mc"].gotoAndPlay(10)
and it will work fine.
however, at the end i'm doing a for loop through each movieclip to set it to the correct place on it's timeline:
ActionScript Code:
for(g=0;g<40;g++){
if (xml_ActualAnswer[g] == user_answers[g]){
this["c"+g+"_mc"].gotoAndPlay(25)
}else{
this["c"+g+"_mc"].gotoAndPlay(37)
}}
and its not working like it does everywhere else.
I have traced different versions:
ActionScript Code:
trace(["c"+g+"_mc"]) //brings up correct mc name
trace(_root["c"+g+"_mc"]) // brings up undefined
trace(this["c"+g+"_mc"]) // brings up undefined
so it seems like ["c"+g+"_mc"] is the only one displaying the correct name but that throws up an error, without 'this' or _root' infront.
Any ideas?
Dynamic Instance Name?
Hi...
I am sure I have seen several of those some time ago, but I don't really recall where they were...
I can do this...
ActionScript Code:
//
var pod0:Pod;
var pod1:Pod;
var pod2:Pod;
for (var i:uint = 0 ; i < 3 ; i++)
{
this["pod" + i] = new Pod();
}
But I cannot type the dynamic instance name like this...
ActionScript Code:
//
for (var i:uint = 0 ; i < 3 ; i++)
{
var this["pod" + i]:Pod = new Pod();
}
So, how do I not define those pod0, pod1 and pod2 like above code block and do something inside the for loop???
Dynamic Instance Name
How do I use a dynamic instace name for a mc
I've tried:
PHP Code:
var arrayCount = usersImages_array.length;
var mc = "myInstanceName"+arrayCount;
_level0."myInstanceName"+arrayCount.loadMovie(_level0.myCombo.getValue());
//ALSO
_level0.mc.loadMovie(_level0.myCombo.getValue());
//ALSO
_level0.eval("myInstanceName"+arrayCount).loadMovie(_level0.myCombo.getValue());
Dave
Dynamic Instance Name
I am current setting the value of a dynamic text field from an XML file using the current script.
MovieClip(root).Bowler1.one_1_1.text = WhosTurn.bowler[0].frameScore[0].attribute("ball2Symbol");
However I would like the instance name of the field( MovieClip(root).Bowler1.one_1_1.text) to be generated using part of the XML.
I have tried doing this - MovieClip(root) + "Bowler1.one_" + WhosTurn.bowler[0].attribute("frameNumber"); but I had no luck,
So I guess to simplify the problem, what is the proper syntax to call an instance name using a combination of text and variables?
Jeff England
Dynamic Instance Name
I am current setting the value of a dynamic text field from an XML file using the current script.
MovieClip(root).Bowler1.one_1_1.text = WhosTurn.bowler[0].frameScore[0].attribute("ball2Symbol");
However I would like the instance name of the field( MovieClip(root).Bowler1.one_1_1.text) to be generated using part of the XML.
I have tried doing this - MovieClip(root) + "Bowler1.one_" + WhosTurn.bowler[0].attribute("frameNumber"); but I had no luck,
So I guess to simplify the problem, what is the proper syntax to call an instance name using a combination of text and variables?
Jeff England
_x In AS For Dynamic Instance Name
Oke, I couldn't find anything about this one...
I have a number of mc's on my mainstage. About ten each named target1, target2 etc.
I have a target problem. I wrote a prototype where I check if a dragged picture (piece1, piece2) is above target1 then... etc.etc.
Working just fine because I stated the coordinates of the image1 etc.
While it's a prototype I thought why not use the _x of image1 ... instead of saying what the _X coordinate is...
Get it so far?
No? this is the prototype I'm talking about....
Code:
// Jigsaw puzzle V1.0 design by www.fromthemill.nl
MovieClip.prototype.jigsaw = function(ocx, ocy, ncx, ncy, pic) {
// ocx = original coordinate x ncx = new coordinate x pic = piecenumber
this.onPress = function() {
_root.i++;
startDrag(this);
this.swapDepths(i);
lines.swapDepths(i+1);
};
this.onRelease = function() {
stopDrag();
var item = "target"+pic;
// item: target is the instance name, pic is declared in my prototype
if (this._droptarget == item) {
this._x = item._x;
this._y = item._y;
} else {
this._x = ocx;
this._y = ocy;
}
delete this.onEnterframe;
};
};
piece1.jigsaw(189, 74, 1);
// so I only state the original x & y coordinates and the piece number
Problem: How to 'target' in AS1 the _x of a " "target"+pic " ???
_x In AS For Dynamic Instance Name
Oke, I couldn't find anything about this one...
I have a number of mc's on my mainstage. About ten each named target1, target2 etc.
I have a target problem. I wrote a prototype where I check if a dragged picture (piece1, piece2) is above target1 then... etc.etc.
Working just fine because I stated the coordinates of the image1 etc.
While it's a prototype I thought why not use the _x of image1 ... instead of saying what the _X coordinate is...
Get it so far?
No? this is the prototype I'm talking about....
Code:
// Jigsaw puzzle V1.0 design by www.fromthemill.nl
MovieClip.prototype.jigsaw = function(ocx, ocy, ncx, ncy, pic) {
// ocx = original coordinate x ncx = new coordinate x pic = piecenumber
this.onPress = function() {
_root.i++;
startDrag(this);
this.swapDepths(i);
lines.swapDepths(i+1);
};
this.onRelease = function() {
stopDrag();
var item = "target"+pic;
// item: target is the instance name, pic is declared in my prototype
if (this._droptarget == item) {
this._x = item._x;
this._y = item._y;
} else {
this._x = ocx;
this._y = ocy;
}
delete this.onEnterframe;
};
};
piece1.jigsaw(189, 74, 1);
// so I only state the original x & y coordinates and the piece number
Problem: How to 'target' in AS1 the _x of a " "target"+pic " ???
Function In A Method Return True To Method's Caller?
I think I probably don't know the correct terminology to ask this question, but here goes:
In this example, can anyone tell me how to have the setComplete event function within the main method return true to the caller of the method, instead of just to the listener?
PHP Code:
function loadAsset(target:MovieClip, asset:String, assetLoaderInfo:LoaderInfo): Boolean { var assetLoader:Loader = new Loader(); var assetURLRequest:URLRequest = new URLRequest(asset); assetLoader.contentLoaderInfo.addEventListener(Event.OPEN, setLoaderInfo); assetLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, setComplete); function setLoaderInfo(event:Event) { assetLoaderInfo = event.currentTarget; } function setComplete(event:Event) { target.addChild(assetLoader); return true; } assetLoader.load(assetURLRequest); }
Function In A Method Return True To Method's Caller?
I think I probably don't know the correct terminology to ask this question, but here goes:
In this example, can anyone tell me how to have the setComplete event function within the main method return true to the caller of the method, instead of just to the listener within the method?
Many thanks!
PHP Code:
function loadAsset(target:MovieClip, asset:String, assetLoaderInfo:LoaderInfo): Boolean
{
var assetLoader:Loader = new Loader();
var assetURLRequest:URLRequest = new URLRequest(asset);
assetLoader.contentLoaderInfo.addEventListener(Event.OPEN, setLoaderInfo);
assetLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, setComplete);
function setLoaderInfo(event:Event)
{
assetLoaderInfo = event.currentTarget;
}
function setComplete(event:Event)
{
target.addChild(assetLoader);
return true;
}
assetLoader.load(assetURLRequest);
}
Dynamic Instance Names
Hi Everyone,
Well, I've been racking my brain on this one now for a couple of hours. I know I'm being an idiot but it's just not coming to me.
What I hoping to do is this. I have six movie clips, with six instance names, screen1, screen2, screen3 etc.
I want to be able to get properties from these movie clips, but I want to be able to create code dynamically. What I mean is I want to write something like:
(screen & x)._y = a;
where x is a variable... thus creating:
screen1._y = a;
hope that makes sense.. anyways.. for the life of me I can't get the syntax right, and now I'm starting to go batty!!
anyways.. any help what so ever would be most appreciated. Thanks in advance.
Pat
Dynamic Referencing An Instance Name
Ok, What I want to do is dynamically reference the instance of an object. My goal is to avoid writing _root.box1.engine.homeX a million times. Everything is the same in this except "box1". Box1 changes from "box1" though "box72" so I am trying to write it in a way that uses the least amount of code. Is their a way to change "box1" on the fly.
Here is the script.
function moveThing(point1, point2)
_root.box1.engine.homeX=point1;
_root.box1.engine.homeY=point2;
}
TextFormat With Dynamic Instance Name
Having trouble applying TextFormat to a textbox with instance generated dynamically.
When a checkbox is checked, italics are applied to 45 textfields. I'm trying to use a for-loop for the text fields rather than apply it to each one individually.
Here's the code:
Code:
if (itbox.getValue() == true) {
fmt = new TextFormat();
fmt.italic = true;
for (i=1; i<=45; i++) {
eval("fx"+i).setTextFormat(fmt);
}
}
I've also tried substituting the line:
Code:
eval("fx"+i).setTextFormat(fmt);
with:
Code:
["fx"+i].setTextFormat(fmt);
and:
Code:
this["fx"+i].setTextFormat(fmt);
and:
Code:
myformat = this["fx"+i];
myformat.setTextFormat(fmt);
but no luck.
if I take out the for-loop and just try one text box:
Code:
fx1.setFormat(fmt);
it works fine. Is there any way to get this loop to work, or an I gonna have to do each one individually?
Path With Dynamic Instance...
Ok heres what my code looks like:
newname = "house"+housedraw;
rightmenu.modules.house.duplicateMovieClip(newname , 15);
now how can I call the instance to set its properties?
neither of these methods work, and i'm confused.
SetProperty(rightmenu.modules.house+housedraw, _x, 1);
SetProperty(rightmenu.modules."house"+housedraw, _x, 1);
setProperty(rightmenu.modules.newname, _x, 1);
Dynamic Instance Problems
ok... so this is supposed to load up an image, and create a nice red border around it. BUT i am having some problems. I had it all working, at one point, but then i put in the bit where the instance will be dynamic (there will be multiple ones that have random names).
could someone tell me why this isn't working?
------
randomize()
function randomize () {
imageCount = random (10)
loadImages (2)
}
function loadImages (imageNo) {
_root.createEmptyMovieClip(["attach"+imageNo], -1);
["attach"+imageNo].createEmptyMovieClip("pic", 1);
["attach"+imageNo].createEmptyMovieClip("frame", 3);
["attach"+imageNo].createEmptyMovieClip("mask", 4);
randImage = random(3);
loadMovie("./Pics/0001.jpg", _root["attach"+imageNo+".pic"]);
_root["attach"+imageNo]._alpha = 50
loadCheckInterval = setInterval(loadCheck(imageNo), 10);
};
function loadCheck (imageNo) {
widdy = ["attach"+imageNo]._width;
if (widdy != 0) {
// trace(widdy)
clearInterval(loadCheckInterval);
drawSquare();
}
};
function drawSquare(imageNo) {
["attach"+imageNo]._alpha = 0;
["attach"+imageNo].frame.beginFill(0x990000, 100);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._x, ["attach"+imageNo]._y);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._width, ["attach"+imageNo]._y);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._width, ["attach"+imageNo]._height);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._x, ["attach"+imageNo]._height);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._x, ["attach"+imageNo]._y);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._x+20, ["attach"+imageNo]._y+20);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._width-20, ["attach"+imageNo]._y+20);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._width-20, ["attach"+imageNo]._height-20);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._x+20, ["attach"+imageNo]._height-20);
["attach"+imageNo].frame.lineTo(["attach"+imageNo]._x+20, ["attach"+imageNo]._y+20);
["attach"+imageNo].frame.endFill();
fadeIn();
}
function fadeIn() {
fadeInInt = setInterval(function () {
["attach"+imageNo]._alpha += 2;
if (["attach"+imageNo]._alpha == 100) {
clearInterval(fadeInInt);
}
}, 10);
}
------
Dynamic Instance Names.
Hey guys,
Hope you can help me...
What Ive made in a movieclip (imageMC1) which just checks a variable and loads a jpg then stops.
I want to be able to duplicate this clip over and over with an incrementing instance name.
This is the code I have (which obviously isnt working).
Any suggestions would rock. Thanks!
x=x+1;
if(x > totalImages){
x=1;
}
_root.loadImage = x + ".jpg";
thisMC = "imageMC" + (x-1);
nextMC = "imageMC" + x
duplicateMovieClip('thisMC', 'nextMC', x)
Working With A Dynamic Instance
I am trying to move a movie clip across the stage. This clip has the instance name "runningGirl". I want to affect this movie clip dynamically. That way, when I add "runningBoy" into the mix, I can use the same function, but pass along the different intance name.
Right now, this is how I'm doing it.
I am calling a function in an if statement:
Code:
if(*parameters*){
ThrowIowan(runningGirl);
}
Then, the actual global function looks like this:
Code:
_global.ThrowIowan = function(iowan){
trace("Big D & the Kid's Table");
dx = 86-_root.iowan._x;
dy = _root.iowan._y-222;
_root.iowan._x += dx;
_root.iowan._y -= dy;
}
It's not working though, because I think it's not reading the instance name right (_root.iowan._x ). I don't think the variable is being passed correctly. How can I make this work?
Note: The function is being called successfully, because the trace shows up.
Dynamic Instance Names
I need to use attachMovie clip feature to my mainSWF. the problem i have is how to label instance names of the buttons that will be duplicated, so i can then assign a new set of commands.
rat
Dynamic Instance Name Assign
hi, i have code
PHP Code:
if (!firstRun) {
aSoldiers = new Array("S11", "S22", "S13", "S24", "S21", "S12", "S23", "S14");
nextOne = 0;
firstRun = true;
//
startPos = 800;
endPos = -100;
timeInSec = 50;
interval = 10;
startScale = 1000;
endScale = 100;
scaleTime = 0.5;
//
}
import mx.transitions.Tween;
import mx.transitions.easing.*;
function tweenNext(mc) {
switch (mc) {
case "S11" :
trace(mc);
new Tween(S11, "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
new Tween(S11, "_yscale", None.easeInOut, startScale, endScale, scaleTime, true);
var tween_handler:Tween = new Tween(S11, "_x", None.easeInOut, startPos, endPos, timeInSec, true);
break;
case "S12" :
trace(mc);
new Tween(S12, "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
new Tween(S12, "_yscale", None.easeInOut, startScale, endScale, scaleTime, true);
var tween_handler:Tween = new Tween(S12, "_x", None.easeInOut, startPos, endPos, timeInSec, true);
break;
case "S13" :
trace(mc);
new Tween(S13, "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
new Tween(S13, "_yscale", None.easeInOut, startScale, endScale, scaleTime, true);
var tween_handler:Tween = new Tween(S13, "_x", None.easeInOut, startPos, endPos, timeInSec, true);
break;
case "S14" :
trace(mc);
new Tween(S14, "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
new Tween(S14, "_yscale", None.easeInOut, startScale, endScale, scaleTime, true);
var tween_handler:Tween = new Tween(S14, "_x", None.easeInOut, startPos, endPos, timeInSec, true);
break;
case "S21" :
trace(mc);
scaleTime *= 0.8;
timeInSec *= 0.8;
new Tween(S21, "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
new Tween(S21, "_yscale", None.easeInOut, startScale, endScale, scaleTime, true);
var tween_handler:Tween = new Tween(S21, "_x", None.easeInOut, startPos, endPos, timeInSec, true);
break;
case "S22" :
scaleTime *= 0.8;
timeInSec *= 0.8;
trace(mc);
new Tween(S22, "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
new Tween(S22, "_yscale", None.easeInOut, startScale, endScale, scaleTime, true);
var tween_handler:Tween = new Tween(S22, "_x", None.easeInOut, startPos, endPos, timeInSec, true);
break;
case "S23" :
scaleTime *= 0.8;
timeInSec *= 0.8;
trace(mc);
new Tween(S23, "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
new Tween(S23, "_yscale", None.easeInOut, startScale, endScale, scaleTime, true);
var tween_handler:Tween = new Tween(S23, "_x", None.easeInOut, startPos, endPos, timeInSec, true);
break;
case "S24" :
scaleTime *= 0.8;
timeInSec *= 0.8;
trace(mc);
new Tween(S24, "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
new Tween(S24, "_yscale", None.easeInOut, startScale, endScale, scaleTime, true);
var tween_handler:Tween = new Tween(S24, "_x", None.easeInOut, startPos, endPos, timeInSec, true);
break;
}
}
//tween_handler.onMotionFinished = function() {
function nextX() {
nextOne++;
if (nextOne>7) {
nextOne = 0;
}
trace(nextOne);
tweenNext(aSoldiers[nextOne]);
}
elInt = setInterval(nextX, interval*1000);
tweenNext(aSoldiers[nextOne]);
and i'd like to simplify it, general problem i have is i don't know how to assign instance names dynamicly, for example from array with eval
PHP Code:
new Tween(eval(aSoldiers[nextOne]), "_xscale", None.easeInOut, startScale, endScale, scaleTime, true);
but does not work
plz help me
[F8] Dynamic Instance Name: Advanced
I am trying to create using Senocular's Motion Path a new Path:
_root.myPath = new Path(parameter1, parameter2);
I want to know if its possible to assign dynamically generated names (such as myPath) and store them in an array and how to reference it for other uses such as:
_root.myPath.lineTo(pointA, pointB);
Dynamic Instance Naming
Hello!
So I'm trying to finish a little image loading class and I'm having lots of trouble scoping the mc's that the images are being loaded into. Let me know if I should post all the files. Basically it seems to work fine, the images load properly, the first 'getChildAt' trace works fine, but a direct trace using the parent.child syntax is giving me 'undefined.' Of course I need to be able to scope those for further use.
Any thoughts or ideas?
Thanks!!
Quote:
code:
private function loadImages ()
{
for (var i:int = 0; i < xmlSrc.image.length(); i++)
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onImageLoad);
loader.load (new URLRequest (xmlSrc.image[i].@url));
}
}
private function onImageLoad (e:Event)
{
clipImg = new MovieClip();
clipImg.addChild(e.target.content);
clipImg.name = "image"+counter;
++counter;
imageHolder.addChild(clipImg);
trace ("Get Child Trace " +imageHolder.getChildAt(0).name); // Traces as "image0"
trace ("Direct Scope Trace " +imageHolder.image0); // Traces as "undefined"
imageHolder.image0.x = 400; // Doesnt work
}
Dynamic Class Instance
Code:
private var styleArray:Array = new Array;
private var styleVar:Boolean = false;
var newMyCellRenderer:Object;
private function setStyles():void {
for(var i:Number = 0; i<cArray.length; i++) {
newMyCellRenderer = new Object;
newMyCellRenderer = MyCellRenderer;
styleArray(newMyCellRenderer);
this.holderMC[cArray[i]].dropdown.setStyle("cellRenderer",styleArray[i]);
}
}
I'm trying to ultimately name a bunch of variables here to create new instances of the MyCellRenderer class. How can I do this?
Thanks.
CreateTextField With Dynamic Instance Name
Hello,
how can I do a TextField with a dynamic instance Name.
A thing like that (I now is wrong):
var textFieldName:String;
textFieldName = 'prova' + i; //i is a variable that change
mcDescrizioniLivello.createTextField(textFieldName , depth.next(),0,0,100, 0);
mcDescrizioniLivello. textFieldName.multiline = true;
I have to do many textField whit different position in a movie clip.
Thanks
Dynamic Class Instance?
Hello,
I wanna know if I can create class instance from string, something like this.
ok:String = "className";
new ok();
or
new "className"();
------------
Dynamic Instance Name In A Tween?
I have a situation where I want to fade the alpha of some displayed movie clips then remove them. Currently I have:
Code:
function propertyClicked():void
{
for(var i:Number = 1; i < displayedProperties + 1; i++)
{
this["tweeny"+i] = new Tween("propIcon"+i, "alpha", Strong.easeIn, 1, 0, 15);
removeChild(getChildByName("propIcon" + i));
}
}
This tells me Cannot create property alpha on String. I also tried like:
Code:
function propertyClicked():void
{
for(var i:Number = 1; i < displayedProperties + 1; i++)
{
this["tweeny"+i] = new Tween(this["propIcon"+i], "alpha", Strong.easeIn, 1, 0, 15);
removeChild(getChildByName("propIcon" + i));
}
}
In this case I get the error: Cannot access a property or method of a null object reference.
I know there must be some way to do this.
Dynamic Instance Names?
say i want to put 30 instances of the ball movieclip on the stage and i want to name them ball1 ball2 ball3 ball4 with a for loop.. how would i do that.... i don't even really know what to call it.. dynamic instance variable names?
thanks in advance.
Dynamic Instance Names
Hey guys,
How can I get this working properly? I cant seem to figure out how to set a dynamic instance of a movieClip with a variable in its name, then reach it...
Thanks!
Code:
var ["feedTextTemp"+i] = new feedTemplate_mc();
holder_mc.content.addChild(["feedTextTemp"+i]);
["feedTextTemp"+objRef.feedid.id].setText(objRef.literal._label + " <b>" + objRef.user1._label + "</b>");
Dynamic Instance Names
I am creating a migration map that is shaded, etc depending on info from an XML file which I can get to load perfectly. However, after that, I don't know WHAT to do so I can't research HOW to do it.
If I return let's say 21 countries from the XML, I need to dynically create 21 instances of a MovieClip. If I run a while "items exist" loop, I can trace each name. What I want to do is to create a dynamic instance name -- i.e., ttFrance, ttIreland, ttSpain when the XML holds records of France, Ireland, and Spain.
Concatenating isn't working. I tried
var "tt"+theXMLData.migration[ctr].title:ToolTip = new ToolTip(); and the compiler didn't like it. I have the linkage correct.
Please point me in the right direction.
Jon
|