AS3 And Variable Scopes
By your help I am able to load an external image and add it as a child to stage but I need also to be able to convert the loader's content to bitmapdata for later use but seems outside the event handler the bitmapdata in null:The trace inside handler function works and the trace at the end shows an error(#1009: Cannot access a property or method of a null object reference.)Could someone please help me understand the scope for "myBitmapData" below, looks like I have mixed old C, Java, PHP and so on scopes together and AS3 in new for me and worst one!Below is the code:import flash.display.*; import flash.events.*; import flash.display.BitmapData;import flash.display.Loader; var myBitmap:Bitmap ;var myBitmapData:BitmapData ;var request:URLRequest = new URLRequest("test.jpg");var myLoader:Loader = new Loader();myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);function onLoadComplete(e:Event){myBitmap = Bitmap(myLoader.content) ;myBitmapData = myBitmap.bitmapData;//trace(myBitmapData.width );}myLoader.load(request);addChild(myLoader);trace(myBitmapData.width );Edited: 01/05/2008 at 07:27:11 PM by Kahama
Adobe > ActionScript 3
Posted on: 01/05/2008 06:47:20 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Variable Scopes
Hi,
If i have a symbol "Menu" and declare a variable like so:
_root.Menu.myVar = 0;
Then i add another symbol in the "Menu" symbol, lets call it "Item".
How do i access the myVar variable from within the "Item" symbol
without going through _root like this:
_root.Menu.myVar
Im looking for something like _level1.myVar or ../myVar or something
like that.
The reon I want to use relative paths is that i am exporting the
Menu symbol to different documents where a absolute path wont work.
Thanks
Variable Scopes In Functions
functions are a godsend, but i'm a little confused as to how to access vars properly in functions.
I have a mc in the root, and inside that mc i want to write a function that interacts with variables inside that movieclip. I can write _root.<nameofclip>.varname, and that works fine, but can I not use _parent.varname within the function to access the same var? I've tried it a few times, and it works sometimes :s
I should just stop being lazy, and run some tests, but i've got 3 projects to finish off b4 hols on friday.. so i dont really have time
tnx in advance, and i hope i've worded it in an understandable way
Two Scopes, Two Blocks, Yet Variable Conflict?
I get 1151: A conflict exists with definition [varName] in namespace internal.
Simple example breakdown:
Code:
var toggle:Boolean = true;
if (toggle == true){
var myState:int = 1;
trace(myState);
}
else if (toggle == false){
var myState:int = 2;
trace(myState);
}
Shouldn't I be allowed to create the variable in both scopes, especially since they are separate scopes, and only one will fire, and I want the variable to not be referenced as soon as either block is done.
I thought whenever you used statement blocks, whether in a for loop, an if statement, or even as just curly braces, they were indeed their own scope?
even simpler example, that generates a warning, and I felt it should not.
Code:
{
var myName="jimmi";
trace(myName);
}
{
var myName="EvilJimmi";
trace(myName);
}
I know this isnt the best practice, this is just to show smallest concept. Ideas? Do i not understand how scope is handled when it comes to curly braces?
yet a third example, that behaves not how i expected. I thought if you declared a variable inside a block, you could not access it after the block exits?
Code:
for (var i:Number = 0; i < 10; i++){
var j:Number = i;
trace(j);
}
trace(j);// outputs 9, but i thought it should be 0, or undefined
Am I going about curly braces all wrong?
Quick Question About Variable Scopes
Hello,
Here is my quick question
for (i=1; i<=5; i++)
{
this["mcName"+i].mcArea.onRollOver = function(){
trace(this["mcName"+i].mcOther);
}
}
How can I get variable "i" to my onRollOver function ? In this example, flash exporting to output panel "undefined" results.
Thanks
Executing A Function Within Several Scopes
Yesterday I read senocular's singular expositions on prototypes (
http://www.flashkit.com/board/showth...hreadid=462834 ) and on inheritance ( http://www.actionscript.org/forums/s...threadid=28710 ) in AS. I feel like I grew 20 years in a couple of hours, and if my head wasn't shaven, it would be full of grey hair. To see the OOP illusion of AS2 crumble to the ground so devastatingly thoroughly! It will be hard to live with this knowledge, having come from a java background and having been lulled into a sense of OOP security by AS2's cunning facade...
In any case, reading senocular's treatises gave me the idea of executing a given function within several scopes at the same time. What I mean by this is that the "this" references in the function can be dereferenced not only to a single "scope" of execution, but to a set of such scopes, in succession. Basically, we can construct, on the fly, an implicit chain of superclass-like instances, execute the function, and successively reset that chain back to its original state.
We can even pass the return value of the function, should it happen to be an Object.
ActionScript Code:
Object.prototype.executeFunctionInMultipleScopes = function(func:Function, scopes:Array, params:Array):Object {
var lastInChain:Object = this;
var toBeReset:Array = [];
// set up the "implicit" superclass proto chain
for (var i:Number=0; i<scopes.length; i++) {
while (lastInChain.__proto__ != Object.prototype) {
lastInChain = lastInChain.__proto__;
}
lastInChain.__proto__ = scopes[i];
// remember which of the protos have to be reset to Object.prototype later
toBeReset[toBeReset.length] = lastInChain;
}
// execute function in the scope of this
var ret:Object = func.apply(this, params);
// reset the required protos in the proto chain to the original Object.prototype
for (var i in toBeReset) {
toBeReset[i].__proto__ = Object.prototype;
}
return ret;
}
// demo
var obj1:Object = {param1:"param1"};
var obj2:Object = {param2:"param2"};
var obj3:Object = {param3:"param3"};
var testFunc:Function = function() {
trace(this.param1);
trace(this.param2);
trace(this.param3);
this.param1 = "overwritten";
}
new Object();
// execute in the initial scope of a new Object, discarding the mutating operations
// that testFunc might attempt (in this case, setting param1="overwritten")
(new Object()).executeFunctionInMultipleScopes(testFunc, [obj1, obj2, obj3], []); // output: param1, param2, param3
// execute in the initial scope of obj1, applying the mutating operations
// to obj1 (in this case, setting param1 of obj1 = "overwritten"
obj1.executeFunctionInMultipleScopes(testFunc, [obj2, obj3], []); // output: param1, param2, param3
trace(obj1.param1); // output: overwritten
You will notice that right after the prototype defnition above there is a call to new Object();. Indeed, I do not understand why it has to be there, and am hoping that senocular or something else will shed some light on this mystery. It seems that simply executing new Object()).executeFunctionInMultipleScopes(...) right after the prototype definition does not work, a dummy new Object() call is needed. Why is that? Immediate execution on obj1 works fine (obj1.executeFunctionInMultipleScopes(...)).
There is indeed something very odd about executing new Object()).executeFunctionInMultipleScopes(...) right after the prototype declaration. Not only it doesn't work, but testFunc becomes undefined!!!!! How is that possible? If, however, we put a trace(testFunc); before doing new Object()).executeFunctionInMultipleScopes(...), then the function call works perfectly! What's going on there?
[edit: changed the traversal of the scopes array to be in the front-to-back order to ensure predictable priority of execution]
How Do I Make A Variable Store A Variable? - Dynamic Input Stuff ...
Hey, I got a little problem which I've usually been able to work around but in this particular case there really isn't another way. I want to give in a variable, say "x+x" and then use it as "x+x" and not as their assigned values ...
my result should be that I can alter the course of a loop like this ... for example:
input in text field = x+x
for(x=0,x<=50,x++){
...
y[x]=x+x
...
}
and if I give in 2*x it would make y[x]=2*x
I have no idea if there's a way in flash to accomplish this but if there is I'd sure like to know, thanks for any help I receive, I'll check back here soon.
Dynamic Text Field Is Calling The Variable Name Instead Of Variable Content
I'm having a problem getting something to work. I'm sure it has something to do with string variables and my syntax, but can't figure it out.
I have variables named cust1, cust2, cust3, etc. that are being loaded from a text file (these are customer names that will display in a text ticker).
I want a dynamic text field to display the customer names in incremental order, so I created a variable that consists of the string "cust" + a numeric variable called custNumber. At the end of each pass of the movie, custNumber is increased by 1.
var custNumber = 1;
var custName = "cust"+custNumber;
I want the dynamic text field to call the variable custName, but I can't get it to work. It keeps displaying custName as a string ("cust1", "cust2", etc.).
So I created a new variable called scrollText for the dynamic text to call, and made scrollText = custName;. But it does the same as above.
How do I get my dynamic text to call the variable that I create with another variable?
I want my dynamic text field to display the variable cust1, cust2, cust3, which would be "Jones Plumbing," "Smith Electric" etc., but all I'm getting is "cust1", "cust2", "cust3" etc.
Thanks,
Thom
Problem Assiging Class Variable To The Main Timeline Variable .... PLEASE HELP
Hi Guys
I just can't seem to solve this problem!!!
I have a random class that generates a random image and an id number from an xml file and a main class that reads information from an xml file according to the id number.
I'm having trouble assigning my random id number from my class to the _root.id variable on the main timeline for my other class to read. I keep getting undefined???
Random Class Code:
Code:
import mx.utils.Delegate;
class randomClass {
public var target_mc:MovieClip;
private var _xml:XML;
private var myTotal:Number;
private var random_number:Number;
public var myFid:Number;
private var myPic:String;
private var myTitle:String;
private var myImages:Array = new Array();
private var myTitles:Array = new Array();
private var myFids:Array = new Array();
function randomClass(url:String, target:MovieClip)
{
target_mc = target;
_xml = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = Delegate.create(this, onLoadEvent);
_xml.load(url);
}
function onLoadEvent(success:Boolean):Void
{
if (success)
{
var i:Number;
myTotal=_xml.firstChild.childNodes.length;
for(i=0; i<=myTotal-1; i++)
{
myImages[i]=_xml.firstChild.childNodes[i].firstChild.firstChild;
myTitles[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.firstChild;
myFids[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.nextSibling.firstChild;
}
random_number=random(myTotal);
myPic="<A href="http://www.mydomain/images/"+myImages[random_number">http://www.mydomain/images/"+myImages[random_number];
myTitle=myTitles[random_number];
myFid=myFids[random_number];
target_mc.title.text=myTitle;
var TheMovieLoader = new MovieClipLoader();
TheMovieLoader.loadClip(myPic, target_mc.new_mc);
var pictureLoaderListener = new Object();
pictureLoaderListener = TheMovieLoader.onLoadComplete()
{
target_mc.new_mc._x=-9;
target_mc.new_mc._y=-5;
target_mc.new_mc._xscale=40;
target_mc.new_mc._yscale=40;
}
TheMovieLoader.addListener(pictureLoaderListener);
target_mc.random_id.onPress = Delegate.create(this, onPressEvent);
}
}
public function onPressEvent() {
_root.id=myFid; //Undefined
trace(myFid); //ok
}
}
Main Movie Code:
Code:
on (press) {
var Obj:myClass=new myClass("<A href="http://mydomain/fanbase.xml",_root.viewer">http://mydomain/fanbase.xml",_root.viewer, _root.id);
}
It just keeps saying undefined but yet i seem to be able to trace myFid
Any ideas???
Thanks in advance
Problem Passing Variable Values (from XML) To Variable In Child Movie
I'm reading something from XML, and store it in a variable. I can trace the variable and it shows two items. I can display those two seperately with variable[0] and [1], meaning that it works as intended.
After that, I'm calling a movieclip, which is supposed to read that variable.. sadly, it can't do it. So I resorted to passing the content of the first variable to a variable inside the called movieclip. This works, and tracing the second variable shows both items from the first. However, I cannot access the items seperately with variable2[0] for example.
What's the problem? The second variable is currently a string. I tried to declare is as other things (like xml or array) as well, but that didn't help. Is there also a way to make this procedure unnecessary, i.e. can I somehow access the first variable?
I've attached the fla/xml/swf in case my description doesn't make sense!
Problem Assiging Class Variable To The Main Timeline Variable .... PLEASE HELP
Hi Guys
I just can't seem to solve this problem!!!
I have a random class that generates a random image and an id number from an xml file and a main class that reads information from an xml file according to the id number.
I'm having trouble assigning my random id number from my class to the _root.id variable on the main timeline for my other class to read. I keep getting undefined???
Random Class Code:
Code:
import mx.utils.Delegate;
class randomClass {
public var target_mc:MovieClip;
private var _xml:XML;
private var myTotal:Number;
private var random_number:Number;
public var myFid:Number;
private var myPic:String;
private var myTitle:String;
private var myImages:Array = new Array();
private var myTitles:Array = new Array();
private var myFids:Array = new Array();
function randomClass(url:String, target:MovieClip)
{
target_mc = target;
_xml = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = Delegate.create(this, onLoadEvent);
_xml.load(url);
}
function onLoadEvent(success:Boolean):Void
{
if (success)
{
var i:Number;
myTotal=_xml.firstChild.childNodes.length;
for(i=0; i<=myTotal-1; i++)
{
myImages[i]=_xml.firstChild.childNodes[i].firstChild.firstChild;
myTitles[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.firstChild;
myFids[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.nextSibling.firstChild;
}
random_number=random(myTotal);
myPic="<A href="http://www.mydomain/images/"+myImages[random_number">http://www.mydomain/images/"+myImages[random_number];
myTitle=myTitles[random_number];
myFid=myFids[random_number];
target_mc.title.text=myTitle;
var TheMovieLoader = new MovieClipLoader();
TheMovieLoader.loadClip(myPic, target_mc.new_mc);
var pictureLoaderListener = new Object();
pictureLoaderListener = TheMovieLoader.onLoadComplete()
{
target_mc.new_mc._x=-9;
target_mc.new_mc._y=-5;
target_mc.new_mc._xscale=40;
target_mc.new_mc._yscale=40;
}
TheMovieLoader.addListener(pictureLoaderListener);
target_mc.random_id.onPress = Delegate.create(this, onPressEvent);
}
}
public function onPressEvent() {
_root.id=myFid; //Undefined
trace(myFid); //ok
}
}
Main Movie Code:
Code:
on (press) {
var Obj:myClass=new myClass("<A href="http://mydomain/fanbase.xml",_root.viewer">http://mydomain/fanbase.xml",_root.viewer, _root.id);
}
It just keeps saying undefined but yet i seem to be able to trace myFid
Any ideas???
Thanks in advance
Problem Assiging Class Variable To The Main Timeline Variable .... PLEASE HELP
Hi Guys
I just can't seem to solve this problem!!!
I have a random class that generates a random image and an id number from an xml file and a main class that reads information from an xml file according to the id number.
I'm having trouble assigning my random id number from my class to the _root.id variable on the main timeline for my other class to read. I keep getting undefined???
Random Class Code:
Code:
import mx.utils.Delegate;
class randomClass {
public var target_mc:MovieClip;
private var _xml:XML;
private var myTotal:Number;
private var random_number:Number;
public var myFid:Number;
private var myPic:String;
private var myTitle:String;
private var myImages:Array = new Array();
private var myTitles:Array = new Array();
private var myFids:Array = new Array();
function randomClass(url:String, target:MovieClip)
{
target_mc = target;
_xml = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = Delegate.create(this, onLoadEvent);
_xml.load(url);
}
function onLoadEvent(success:Boolean):Void
{
if (success)
{
var i:Number;
myTotal=_xml.firstChild.childNodes.length;
for(i=0; i<=myTotal-1; i++)
{
myImages[i]=_xml.firstChild.childNodes[i].firstChild.firstChild;
myTitles[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.firstChild;
myFids[i]=_xml.firstChild.childNodes[i].firstChild.nextSibling.nextSibling.firstChild;
}
random_number=random(myTotal);
myPic="<A href="http://www.mydomain/images/"+myImages[random_number">http://www.mydomain/images/"+myImages[random_number];
myTitle=myTitles[random_number];
myFid=myFids[random_number];
target_mc.title.text=myTitle;
var TheMovieLoader = new MovieClipLoader();
TheMovieLoader.loadClip(myPic, target_mc.new_mc);
var pictureLoaderListener = new Object();
pictureLoaderListener = TheMovieLoader.onLoadComplete()
{
target_mc.new_mc._x=-9;
target_mc.new_mc._y=-5;
target_mc.new_mc._xscale=40;
target_mc.new_mc._yscale=40;
}
TheMovieLoader.addListener(pictureLoaderListener);
target_mc.random_id.onPress = Delegate.create(this, onPressEvent);
}
}
public function onPressEvent() {
_root.id=myFid; //Undefined
trace(myFid); //ok
}
}
Main Movie Code:
Code:
on (press) {
var Obj:myClass=new myClass("<A href="http://mydomain/fanbase.xml",_root.viewer">http://mydomain/fanbase.xml",_root.viewer, _root.id);
}
It just keeps saying undefined but yet i seem to be able to trace myFid
Any ideas???
Thanks in advance
About Refreshing The Value Of A Variable Inside Of Another Variable (in A Text Field)
Hello, I have a simple question, but I'm not sure this is possible in Flash:
I'll simplify the problem so that it's easy to understand.
I have a text field holding a variable called "products".
This variable is defined via ActionScript somewhere else, with something like this:
Code:
products = "Some text here" + variable1;
The problem is that, when "variable1" is updated, the value of "products" will obviously remain the same, as it hasn't been redefined (I could redefine it as [products = products + ""] or something, but if I don't include the "variable1" in the definition it won't pick its new value).
I really need to do this with just one text field, and I cannot redefine the whole variable "products" again, as it is much complex than this example and keeps storing info in different ways depending on what the user does.
Any suggestions?
Thanks in advance
How To Store A String Plus A Variable In A Dynamic Text Variable?
Hi,
I've got a dynamic text field with the instance name rightAnswer_txt.
I declare the variable in the frame it resides in, with the following code var rightAnswer_txt:String = "";
Then, when I want to populate it using the following code:
rightAnswer_txt.text = "You scored " + rightAnswers;
the script comes out with an error saying ...
**Error** Scene=Scene 1, layer=actions, frame=7:Line 15: There is no property with the name 'text'.
rightAnswer_txt.text = "You scored " + rightAnswers;
Any idea what this means anyone please?
Variable Scope - Dynamically Created Variable Not Working
Hi all,
For a movieclip obj, I created a dynamic variable and in the onLoadInit handler this variable is not accessible.
This is my code:
--------
var imagesList:Array = new Array("flagGreen.gif", "flagRed.gif");
var path = "images/";
var myMc:MovieClip
= _root.createEmptyMovieClip("myMc", _root.getNextHighestDepth());
myMc.url = path+imagesList[0];
var loader = new Object();
loader.onLoadInit = function(targetMc){
trace( "url1:"+targetMc.url);
trace( "url2:"+_root.myMc.url);
trace( "width:"+targetMc._width);
trace( "height"+targetMc._height);
}
var mcLoaderObj:MovieClipLoader = new MovieClipLoader();
mcLoaderObj.addListener(loader);
mcLoaderObj.loadClip(myMc.url, myMc);
-----------
Image is getting loaded. When myMc.url is passed as a param to loadClip, it is working, but inside onLoadInit it is printed as undefined.
Help will be appreciated. Thanks in advance.
- Kiran
Variable Take On Content Of A Root Variable And Not Its Path - Simple Please Help
Hi there ok my brain has died and fallen off somewhere , what i am trying to do is this:
l=0
l++
_root.advert= "_root.var" + l ;
then i have a text box on stage , dynamic, etc var: _root.advert
, vars are stored in a text file , vars are called, var1, var2 etc , text box needs to display variable contents, but at the moment it just says "_root.var1" etc and not the content s of var1 this is very simple problem but my brains dead please help.
-arran
Loading Variable Smarclip Into Variable Movieclip?
HO HO HO FashMonsters-
Damn, Loading a variable driven smartclip into a movie clip can be a lil' tricky. Problem is I think I need the movie clip to be a variable as well. My button action is calling up my movie clip instances which are referencing the variable smart clip. However, each button action loads a new movie clip atop the previous. I either need to remove the previous movieclip or make the movie clip a variable loading variable smart clips.
Da Dizawg wud LUV some Hizelp!
Dynamic Text Box Variable = Other Variable, No More Scroll
So I have this textbox. And I want it to display some text. And I want the text to scroll and I want the text to change when you click a button. W007 I did it I am done. But I have a little problem, and I do hope you can help.
I loaded variables from a text file into flash, gave the variables different names, and then I set the buttons that can be clicked on to set the dynamic text box variable to equal one of the loaded variables. Ít wouldn't scroll after that. Whats up wit dat.
I can get you the FLA if you want it, but I am hoping someone will just say oh ya, common mistake, you gotta check a box or something.
Make A Variable = A Variable From A Text Document
I'll try my best to explain this, but it might be easier to see the file itself, I zipped it up and can be found at:
DOWNLOAD ZIP FILE
(the flash file is not pretty, I am building the functionality first)
-----------------------------
The variable it is creating does not call up the variable in the text
document.
I have a textfield called: randomquote
the value for randomquote is being "created" by:
Set Variable: "randomquote" = "q"&VARX2
VARX2 is a random number being generated by:
Set Variable: "VARX2" = Random ( VARX )
VARX is a number being pulled from the text document:
Set Variable: "VARX" = (/:myNumber)
SO, If I hard code randomquote with the value q4 , then the variable q4 from the textdocument is pulled up correctly.
BUT, if randomquote equals q4 (generated from a random number) the variable q4 from the textdocument is not shown, but rather just a simple q4.
Passing Array Variable Name In To Component Variable & Getting It's Value
Hi, All
Anyone can solve my problem????
My Problem is that I want to store a array' s name in to a component variable. like this:-
working in this case
Scene action on timeline
_global.arr = "This is aray Test"
component parameters
VarName : _global.arr
Not working in this case
Scene action on timeline
_global.arr1 = new Array()
_global.arr 1[0]= "This is aray Test"
component parameters
VarName : _global.arr1[0]
in component I'm doing this on timeline action
abc.text = eval(VarName)
plz help me out of this
Regards
Ankur Arora
Php Variable -> Actionscript Variable (transfer Without Being Seen By User)
I am trying to secure up the sign up process with something similar to the "type these 6 letters"
the problem is, how to get a value between php(or any server-side language) and actionscript? I only know ways where the variable would be visible to a robot, rendering this extra sign-up step useless.
So I am wondering if there is a way to transfer a variable without it being seen during transfer?
I have a little bit of knowledge about public variable encryption and I know it would work for this but i have never implemented this encryption before. Is there a tutorial that shows how to go about creating a public encryption/decryption algorithm?
Change String Variable To A MovieClip Variable
Hi
I have been banging my head against a brick wall regarding the following problem which must be very simple to fix, just can't see the answer.
I have a class assigned to a movieclip called canvas. The class is called drawClass. I have called the instance of canvas on the stage 'drawingCanvas'.
When I trace "drawingCanvas" I get
[object drawClass]
which is fine. Tracing drawingCanvas.name gets me the instance name
'drawingCanvas'.
This is a String variable.
Basically what I am trying to do is pass the MovieClip name to another class. In my example the class 'toolBar', which can then interact with the MovieClip.
The problem is passing 'drawingCanvas.name' results in a String, so I get an error saying :
TypeError: Error #1034: Type Coercion failed: cannot convert "canvasArea" to flash.display.MovieClip.
I can't for love or money find a way to convert a String variable to a MovieClip variable! I have the name of the MovieClip, I just need to tell the toolbar class. But I can't find a way of doing this as the instance on stage is an object of drawingClass, not a MovieClip (unless MovieClips with attached classes are not treated as standard MovieClips?).
Any ideas are most welcome. I'm sure I am missing something obvious.
Thanks for looking
Sting Variable To Mc Path - VARIABLE TYPES
Hey all Im building a variable like this
var m = "_root.subNav.subNav" + i;
When I do a trace to find the var type it comes back as a string so my function wont execute thinking it is a string and not a path. Does anyone know how to fix this or change the variable type on the fly in AS 1.0? Ive tried:
var m =eval( "_root.subNav.subNav" + i);
But that came back undefined....
Thanks.
Changing Root Variable With Text Variable
Simple question: I'm trying to change the value of a variable on the _root level (called "myVar") to whatever a user types into a text box (mytextvar) on the stage. I have a button that says:
ActionScript Code:
on (press) {
_root.myVar = _root.myTextVar;
}
It isn't working... any ideas how to make this work?
Apply Variable Values To Variable Names?
I have a gallery with a series of 5 thumbnails, named gallery_position_1, gallery_position_2, etc, up to 5. I am loading an image with XML into gallery_position_(#), and have a button on top of that with scripts on it.
My question is whether I can have an integer variable (call it x) that starts at 1 and can be put into a for loop, using it then on the end of my other variable like so:
for (x = 1; x < 6; x++) {
gallery_position_x.loadMovie(URL path to image);
}
I basically want to be able to "index" a regular variable by changing a number within its name. I know its a long shot, as I've never seen it done before, but I thought I'd ask, all the same.
Convert String Variable Into Movieclip Variable?
I have a variable called something like city_str which has a value of "toronto". I also have a moveclip (exported for AS) called toronto_mc.
What I want is a way of concatenating strings of "toronto" and "_mc" and assigning it to a movieclip variable called toronto_mc. Everything I try gives me a mismatch error in the compiler. I'm writing AS2 using Flash CS3. Any ideas?
Overwrite Variable Versus Delete Variable
I'm assuming that if you were to create a variable that referenced an instance of a class, then if you were to overwrite that variable with an instance of a new class, the old class would be deleted without explicitly deleting that class. Am I correct in assuming this?
Can't Update Movie Variable With Loaded Variable
i have a php file that loads an array of variables with paths that load into some text fields in duplicated movie clips. The php path is right, but it just doeasn't load them into the txt fields. How do i get and set the variables???
this gets loaded into th movie from the php file;
_level0.work.client_mc6.web_work.web_mc0.file0 = "rm1.jpg"
but it doesn't replace what is already in there??!!
_level0.work.client_mc0.web_work.web_mc0.file0 = "remove me"
how do i update the old vaiable with the one tha'ts loaded via PHP?
|||---> Variable Textfields And Variable Sizes?
ok... i'm trying to add tool-tips
i would like to have the dynamic textbox (which follows the mouse) resize itself based on the /:tip variable i have created
so that if /:tip = "" no textbox appears
and if /:tip = "flash 20k" the textbox would be the right size to fit the text
i'm trying to do this with the background feature turned on, so that the text is black on white
---
can anyone point me in the right direction?? much appreciated
-steve
Set Variable: Setting Variable Name Dynamically
hi...
i want to set a variable dynamically, i have done:
soundCount = 5
set (eval("loading"+SoundCount), 1);
i want the outcome as:
loading5 = 1
which i wanna check later...
is it right? because i m not getting the result when i
trace (loading5)
please help
Variable In Movie Clip With A Variable Name
Hello,
I need to find out the content of a variable in a Movie Clip with a variable name. I created several movie clips with "duplicateMovieclip" in a for... loop. Looks like this:
for (i=1; i<=5; i++) {
duplicateMovieClip (_root.oldname, "newname"+i, i);}
Now I want to know and set the content of a variable stored in this clip, but again in a for.... loop.
I tried it with:
"_root.newname"+i+".variable"=content;
This does not work. Anyone any ideas?
Thanks for any answer that might help me.
Greetings from cologne
Ole
Setting The Value Of A Variable, Checking The Value Of A Variable
i think this might be a simple question, but I can't figure it out and it's puzzled me for a long time. If I set a variable OnRelease - let's say I have 4 buttons that set a variable to 4 distinct values, depending upon which button is pressed. How do I create a check, later, from another part of the movie, for what the current value of that variable is?
Is the variable universal - that is once it is set, the entire movie sort of 'knows' what the value of that variable is? Or do I have to direct the attention of the movie back to the same clip or frame or wherever I set it. Either way, what is the syntax?
I hope I was able to explain this and that it makes sense to someone.
Thank you!
-ml
Variable Names Are Part Of A Variable Itself
hello,
i ahve a deadline and im in a bit of a mess, i was wondering if anyone knows the awnser to this one.
i am targeting a variable in another movie the name of the variable is ' ysh1 ' this is a score and the is 9 other they are ' ysh2 ' , ' ysh3 ' etc.
and a variable on the main time line called ' hole ' ,
it's value is ' 1 '.
this is the variable that targets ' ysh1 '.
set ("_level0.display.score.ysh"+_level0.hole, "_level0.display.score.ysh"+_level0.hole+"+1") ;
so it does target the variable, that works fine but i cant make the score increase by 1
im just try to increase the score by one evey time this function is called.
it's driving me mad.
any help would be great.
_root.variable -> Object Variable
Hi,
I am rather new to flash, so please bear with me
I've downloaded a flashmovie at http://www.flashkit.com/movies/Inter...8449/index.php ( a very beautiful window navigation menu).
The menuitems to build this window-menu are placed within the object as variables.
I want to put these variables into the root timeline (where I can retreive menuitems from a database). The object however cannot retreive variables from the root-timeline it appears.
I've tried using _global.varname in the root timeline, but it didn't help.
Is there a way I can make these variables appear within the object?
help appreciated
Patrick
Creating A Variable The Name Of The Contents Of Another Variable
Hi all
I've got a variable called "test"
Within "test" there's the string "monkey"
I want to create a variable called "monkey" in another movieclip and add a string to it.
How do i do this?
I've tried _root.movieclip.eval(test) = "blah"
But this generates an error....
any ideas?
Many thanks
Converting Variable Contents Into A Variable Name?
Hi
How do you convert variable contents into a variable name?
ie
var Monkey:String = "ape";
how do I then make
var apeBanana:String;
I've tried
var [monkey+"Banana"]:String;
but that doesn't work, any suggestions appreciated :-)
How To Put External Variable's From PHP Into Variable's In A Function
I already echo my variable's the right way. I want to make it possible to adjust collors trougout my database. This is what my PHP file echos:
&homecolor=33ff33&newscolor=000000
this is how my PHP file looks:
PHP Code:
<?php
require("connection.inc.php");
$query = "SELECT name, color FROM outlinecolors";
$result = mysql_query($query);
while(list($name, $color) = mysql_fetch_row($result)) {
print("&$name=$color");
}
?>
This way of using PHP also works for the text I use in my movie, which I let flash put in a dynamic textfield. So I tought that it should be possible to have the variable colors above being used in the next function:
code:
home_btn.onRelease = function() {
outline.fadeColor(homecolor, 100, tweensspeed, test);
};
"homecolor" is the place where the value/echo from php must come (&homecolor=33ff33) so "33ff33" must be in the function in stead of homecolor.
Can anybody help me?
Greets..
Make A Variable Equal Another Variable
Code:
set ("variable1",variable2.value);
Forgive this stoopid question but what's the right syntax here
I want to set a string variable called variable1 to equal the string variable called variable2.
TIA
Variable From Flash As Childnode Variable
Is it possible to take a variable from Flash and use it as an xml childNode variable?
Code:
function loadXML(loaded) {
if (loaded) {
i = int(_root.shoe_id);
_root.shoe = this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
_root.shoe_color = this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
shoe_txt.text = _root.shoe;
shoe_color_txt.text = _root.shoe_color;
} else {
content = "info unavailable";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("brand_info.xml");
Javascript Variable To Flash Variable Name
I have a weird situ. where I have to convert a javascript string var into a flash var, but its not your typical value conversion.
I need to convert the javascript string value to flash's variable name.
in other words:
Code:
javascript:
function startMov()
{
elem.SetVariable("/variables:startStation", "stationA");
elem.SetVariable("/variables:endStation", "stationB");
elem.TCallLabel("/functions","setStation");
}
in Flash the "variables" MC:
var stationA = 239;
var stationB = 412;
var startStation;
var endStation;
_root actions:
setStation = function () {
currentStation = variables.currentStation;
startAtStation = variables.startStation;
stopAtStation = variables.endStation;
up_hall.gotoAndPlay(startAtStation);// no problem here, because its a string
stopAtEndStation();
};
stopAtEndStation = function () {
this.onEnterFrame = function() {
if(up_hall._currentframe == stopAtStation){
up_hall.stop();
delete onEnterFrame;
}
};
};
So when I pass in "stationA" I need for the value to be the integer 239.
I have tried to eval the var, but I just get "undefined"
[F8] _root.Variable VD _global.variable
Hi! This code i need help with is just for learning purpose, im not really trying to acomplish a certain thing. Just to understand more about AS.
FLASH 8
I have dynamic text box thats reading the variable _root.my .
In the first frame i have this
Code:
_root.my = "So long Jerks!";
i have a MC as buton with following
Code:
button.onPress = function (){
_root.my = "goodbye";
}
This is all cool. I try the movie and, WUEPA! the text box says "so long Jerks!". When i click the button the text chabges to "goodbye".
When i exchange _root.my for _global.my in all the before mentioned places., nothing works. The dynamic textbox never shows anything.
How do i use _global variables?
Comparing Javascript Variable Against An XML Variable
Hi,
I currently send a url variable (using javascript) into my flash movie.
I want to compare this variable against a name in an XML file and where they match show the images associated with those XML nodes.
e.g. I have the following xml:
Code:
<gallery cityname="london" xpos="0" ypos="0">
<image path="images/1.jpg" />
<image path="images/2.jpg" />
<image path="images/3.jpg" />
</gallery>
Say my variable name is "london" (from the URL http://www.thisisatest.com/test.html?city=london)
How can I compare this variable against cityname="london" from my XML file and display the images where they match?
Thanks
[CS3] [AS2] Using Variable Text Contents As Another Variable's Name
Hi guys. I was wondering if there was a way to use a variable's contents (such as an input text box's contents) as the name of another variable. Both variable will be global. So, if the text box's instance name is "txt_box" and
Quote:
txt_box.text = _global.hello
how would I use the contents of _global.hello as the name of another variable? I think it's something like
Quote:
_global[[_global.hello]] = "text";
or something along those lines.
Thanks,
Sportzguy933
Variable = Variable -1 = Broken Math?
Hi there,
At the beginning of my flash file, I have:
var beers:Number = 0;
Later in my game you can use your money to buy a beer, the code goes:
beers = beers +2
The code for when you drink the beers goes:
beers = beers -1
HOWEVER,
When you get down to 1 beer, and drink a beer, it goes to -1.
Anyone know why???
Setting A Variable Thats Contained In A Variable
This might sound confusing but I am trying to reduce my lines of code by making it more effecient. I want to save the name of a variable into a variable so for example...
_root.number = 50;
_root.saveVariable = _root.number;
Now how do I change _root.number by only using _root.saveVariable?
I am thinking it has something to do with brackets or parenthesis. Any help is appreciated this has really been bugging me.
New Variable = Global Variable Not Working
Could someone please explain why, when I add var newArray = _global.nameA[0], and try to trace newArray, it returns undefined, but returns the correct variable with _global.nameA[0]?
ActionScript Code:
xmlData.onLoad = function(success) {
if (success) {
_root.showXML = this;
var comp = xmlData.firstChild.firstChild.childNodes;
_global.nameA = [];
for (i=0; i<comp.length; i++) {
_global.nameA[i] = this.firstChild.firstChild.firstChild.nodeValue;
}
//var newArray = _global.nameA[0];
playButt.onRelease = function() {
trace(_global.nameA[0]);
//trace(newArray);
};
Many thanks in advance
|