Xml.onLoad variables undefined outside function
Hi all,
I've been searching this problem for a while and have tried a number of solutions found on google but nothing has worked so far. I'm sure this is a common problem, but due to my lack of flash knowledge I can't logically work through it as I'm used to windows form development, it makes sense to me that the function could access the variables I have defined but they dissapear after the .onLoad event. Does anyone know the common solution to this problem? I want to be able to pass the xml details into the local variables so I can pass on the details into a dynamic text field when movies are hovered over etc.
Thanks in advance for any help.
var myXML:XML = new XML();
myXML.ignoreWhite=true
var nav1TitleText:String;
var nav1Text:String;
var nav2TitleText:String;
var nav2Text:String;
var nav3TitleText:String;
var nav3Text:String;
var nav4TitleText:String;
var nav4Text:String;
myXML.load("navigation.xml");
myXML.onLoad = function(success){
if (success){
nav1TitleText = myXML.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
trace(nav1TitleText); \\ This one shows the text from the xml file
nav1Text = myXML.firstChild.childNodes[0].childNodes[2].firstChild.nodeValue;
nav2TitleText = myXML.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
nav2Text = myXML.firstChild.childNodes[1].childNodes[2].firstChild.nodeValue;
nav3TitleText = myXML.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue;
nav3Text = myXML.firstChild.childNodes[2].childNodes[2].firstChild.nodeValue;
nav4TitleText = myXML.firstChild.childNodes[3].childNodes[1].firstChild.nodeValue;
nav4Text = myXML.firstChild.childNodes[3].childNodes[2].firstChild.nodeValue;
trace(nav1TitleText); // This one traces undefined
Thanks for your help, I have got it working now by doing as you suggested. In .net programming when you specify something to load, it will run the onload first, and then continue through to the rest of the code. I'm assuming flash runs all of the code (non-functions) regardless of order of code. So it was running the trace below the onLoad before the onLoad, even though I told it to myXML.Load() before the other code...
Seriously doesn't make sense to me.. lol
var myXML:XML = new XML();
myXML.ignoreWhite=true
var nav1TitleText:String;
var nav1Text:String;
var nav2TitleText:String;
var nav2Text:String;
var nav3TitleText:String;
var nav3Text:String;
var nav4TitleText:String;
var nav4Text:String;
myXML.load("navigation.xml");
myXML.onLoad = function(success){
if (success){
nav1TitleText = myXML.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
trace(nav1TitleText);
nav1Text = myXML.firstChild.childNodes[0].childNodes[2].firstChild.nodeValue;
nav2TitleText = myXML.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
nav2Text = myXML.firstChild.childNodes[1].childNodes[2].firstChild.nodeValue;
nav3TitleText = myXML.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue;
nav3Text = myXML.firstChild.childNodes[2].childNodes[2].firstChild.nodeValue;
nav4TitleText = myXML.firstChild.childNodes[3].childNodes[1].firstChild.nodeValue;
nav4Text = myXML.firstChild.childNodes[3].childNodes[2].firstChild.nodeValue;
loadedValues();
function loadedValues()
trace(nav1TitleText);
navItem1.title1.text = nav1TitleText;
navItem2.title2.text = nav2TitleText;
navItem3.title3.text = nav3TitleText;
navItem4.title4.text = nav4TitleText;
Thank you again for your reply!
Bex
Similar Messages
-
Xml.onLoad variables undefined outside
Hi all,
I've been searching this problem for a while and have tried a number of solutions found on google but nothing has worked so far. I'm sure this is a common problem, but due to my lack of flash knowledge I can't logically work through it as I'm used to windows form development, it makes sense to me that the function could access the variables I have defined but they dissapear after the .onLoad event. Does anyone know the common solution to this problem? I want to be able to pass the xml details into the local variables so I can pass on the details into a dynamic text field when movies are hovered over etc.
var myXML:XML = new XML();
myXML.ignoreWhite=true
var nav1TitleText:String;
var nav1Text:String;
var nav2TitleText:String;
var nav2Text:String;
var nav3TitleText:String;
var nav3Text:String;
var nav4TitleText:String;
var nav4Text:String;
myXML.load("navigation.xml");
myXML.onLoad = function(success){
if (success){
nav1TitleText = myXML.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
trace(nav1TitleText); \\ This one shows the text from the xml file
nav1Text = myXML.firstChild.childNodes[0].childNodes[2].firstChild.nodeValue;
nav2TitleText = myXML.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
nav2Text = myXML.firstChild.childNodes[1].childNodes[2].firstChild.nodeValue;
nav3TitleText = myXML.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue;
nav3Text = myXML.firstChild.childNodes[2].childNodes[2].firstChild.nodeValue;
nav4TitleText = myXML.firstChild.childNodes[3].childNodes[1].firstChild.nodeValue;
nav4Text = myXML.firstChild.childNodes[3].childNodes[2].firstChild.nodeValue;
trace(nav1TitleText); // This one traces undefinedHi, thanks for your reply. For some reason I've ended up with two of the same posts.
The other one is here: http://forums.adobe.com/message/2204418#2204418 and has been answered.
Cheers,
Bex -
_global variable lost outside of function?
Vexing riddle: why are my global variables undefined outside
of the functions that use them?
Loading XML file and creating arrays from the child nodes.
Like this:
var modules:Array = this.firstChild.childNodes;
_global.moduleContents = new Array();
for (var i = 0; i<modules.length; i++) {
_global.moduleContents.push(modules
.attributes.contents);
then I have another function that recursively extracts each
index from _global.moduleContents array and pushes them into a
_global. pageContents array. (see attached code)
I made sure to use _global. in front of all global variables.
The code workd flawlessly in itself. I am able to trace the whole
array or single array indices from within the functions.
But they are undefined outside of the functions! I checked to
make sure there is no local variable of the same names - in every
case I use _global before the variable name.
The crazy part of it is I tried testing some simple functions
with global variables in a new movie to understand the scope issues
and they worked fine!
function messages() {
_global.greetings = ["hello", "hi", "how are you?"];
function sayHi() {
_global.greetings.push("how goes it?");
sayHi();
messages();
trace("this is outside: "+_global.greetings);
Why not in this:Gotcha, what is happening is that you call a loading script
that basically works in the background of other scripting
operations, you can call multiple load actions and they will all
execute at the same time, because you have your trace call after
the load action and you are not waiting for that file to be loaded
you are getting an 'undefined' var.
You may want to put something in at the end of all of your if
(success) statements like
_global.docstructureLoaded = true;
checkLoadStatus();
then say this on your next load function;
_global.pageContentsLoaded =true;
checkLoadStatus();
then in your root area
checkLoadStatus(){
if(_global.pageContentsLoaded==true && .... ){
//when all your loads are done do this ...
Just to make sure that you arn't calling any other functions,
or moving your timeline ahead before your data gets to the right
place. -
Losing variable values between functions...
hi!
I'm trying to do something simple in actionscript as simple as this:
- Create a variable: var urlVideo:String;
- Use that variable inside a function and give it a value: urlVideo = videoElemento.url.text();
- Then create a new variable and give it the urlVideo value: var url:String = urlVideo;
My problem is that urlVideo loses it's value
Why is that happening?
Here's my code:
var idVideo:String = "12";
var urlVideo:String;
var xmlPath:String = "videos.xml";
var xml:XML;
var loader = new URLLoader();
loader.load(new URLRequest(xmlPath));
loader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(e:Event):void
if ((e.target as URLLoader) != null )
xml = new XML(e.target.data);
xml.ignoreWhitespace = true;
getVideo(xml);
function getVideo(videosInput:XML):void
var listaVideos:XMLList = videosInput.Video;
for each (var videoElemento:XML in listaVideos)
if(videoElemento.id.text() == idVideo)
urlVideo = videoElemento.url.text();
trace(urlVideo); //has a value
break;
var url:String = urlVideo; //the urlVideo values is null !!
What am i doing wrong?
Can anyone help me?The above post is correct providing the way you displayed the code in your original post is the same way you have it in your program
function getVideo(videosInput:XML):void
var listaVideos:XMLList = videosInput.Video;
for each (var videoElemento:XML in listaVideos)
if(videoElemento.id.text() == idVideo)
urlVideo = videoElemento.url.text();
trace(urlVideo); //has a value
break;
var url:String = urlVideo; this line occurs outside the function which means that until getVideo is called urlVideo will always be null because its never set until getVideo actualy gives it a value.
zeroskillz method will set the url to play right inside the function which is a good way to organize.. keep behaviors together.
now if you placed url= urlvideo before the end of the function you would have seen a trace like thus:
function getVideo(videosInput:XML):void
var listaVideos:XMLList = videosInput.Video;
for each (var videoElemento:XML in listaVideos)
if(videoElemento.id.text() == idVideo)
urlVideo = videoElemento.url.text();
trace(urlVideo); //has a value
break;
var url:String = urlVideo //has value -
[Bash] How to `declare` a global variable inside a function?
#!/bin/bash
# Not using declare -A, array will be treated as indexed array rather than an associative array
seta()
for ((n=0;n<$1;n++)); do
printf -v a_$n[k] %s k$n
printf -v a_$n[j] %s j$n
eval echo inside seta: a_$n[k] = \$\{a_$n\[k\]\}
done
seta 3
echo outside: a_0[k] = ${a_0[k]}
echo outside: a_0[j] = ${a_0[j]}
echo
# Use declare -A inside function, array will be undefined outside
setb()
for ((n=0;n<$1;n++)); do
declare -A b_$n # Note here
printf -v b_$n[k] %s k$n
printf -v b_$n[j] %s j$n
eval echo inside setb: b_$n[k] = \$\{b_$n\[k\]\}
done
setb 3
echo outside: b_0[k] = ${b_0[k]}
echo outside: b_0[j] = ${b_0[j]}
echo
# The bad solution, only works if we know beforehand how many c_? arrays will be assigned inside setc()
for ((n=0;n<3;n++)); do
declare -A c_$n
done
setc()
for ((n=0;n<$1;n++)); do
printf -v c_$n[k] %s k$n
printf -v c_$n[j] %s j$n
eval echo inside setc: c_$n[k] = \$\{c_$n\[k\]\}
done
setc 3
echo outside: c_0[k] = ${c_0[k]}
echo outside: c_0[j] = ${c_0[j]}
My original code does the declare -A as in setb(). I was surprised when I saw all blank output... Now the problem is illustrated clearly by the setb() example.
The setc() example works, but a bit ugly: look at the two 3's...
My ideal solution would be, something like `declare_global -A b_$n` in setb()
Any ideas?with current bash versions, i don't think it is possible to declare global associative arrays in functions.
what you are after is the "-g" option of typeset which is available in zsh.
i think i read somewhere that something similar may be planned for bash 4.2. -
LoadMovie() & XML.onLoad query(AS2)
Hi all :)
I have a Flash file that uses the loadMovie () to load JPG
files successfully, example:
imageuri = "../images/00_proto" + var1 + ".jpg";
holder_mc.holder0.loadMovie(this["imageuri"]);
Working
Example
'holder_mc' is the container clip and 'holder0' is the clip
that stores the loaded JPG file, this works fine.
I am upgrading the Flash file using an XML database, code
example:
var statesXML:XML = new XML();
statesXML.ignoreWhite = true;
statesXML.load("../XML/USA.xml");
statesXML.onLoad = function(success)
// XML loading excluded
// Problem code
imageuri = "../images/00_proto" + var1 + ".jpg";
_parent.holder_mc.holder0.loadMovie(this["imageuri"]);
The JPG's are not being loaded into the 'holder0' clip from
inside the XML.onLoad() method. Spent hours trying to fix this,
still have not resolved the problem. Any responses much welcomed!
regards
John
www.javono.comHi John,
Its diffcult as I don't know what you've tried before, but my
first stop would be to trace out imageurl to make sure the path to
the image is correct (although usually you'll get an error message
if not). Are you sure you need _parent. on the start of that path?
Have you tried it without that?
Tom. -
Can a Variable represent a Function?
Is there a way I can assign this code
"SimpleButton(event.target).mouseEnabled = false;" to a variable so
I can disable all the buttons where n=1?
Something like this (sorry, I'm not sure of the proper syntax
which may be my problem):
var n:Number = 0;
if (n = 1)
SimpleButton(event.target).mouseEnabled = false;
else
SimpleButton(event.target).mouseEnabled = true;
OR
Maybe a variable inside the function to represent the True or
False?
where n = 0 = True
and n = 1 = False
SimpleButton(event.target).mouseEnabled = ('n' instead of
true or false);
I have 10 buttons on the page and when one activates a movie
I want all the buttons to be deactivated except the "close" button
and I thought using a variable like "n" would allow me to do this.
Currently with the above code I get "Access of undefined
property event" error where this line of code is located.
ksVery Sorry, but I can't make anything out from your code or
how I'm suppose to use it. I've only been using CS3 for 4 weeks and
it just doesn't make sense and nothing in my books or the searches
or Flash Help explains it so I can understand it.
var tl:MovieClip = this; (what is going on with this
variable? It looks like its turning a button click target into a
movie..?)
var buttonNum:int = xxx; // <--define this (is this the
total # of buttons I'm using? I'm guessing it is)
(the below increments my coin buttons to their instance names
of coin1, coin2, etc. but how does it relate to tl[coin"+i]?)
for(var i:int=0;i<=buttonNum;i++){
tl["coin"+i].addEventListener(MouseEvent.CLICK,f);
( is the below where I want to insert the code to disable the
buttons like this code? SimpleButton(event.target).mouseEnabled =
false;)
(also, should it be event:MouseEvent not e:MouseEvent?)
function f(e:MouseEvent){
// now you can do whatever with your buttons
// e.currentTarget is the clicked button
Sorry for the head aches but thanks for the help you have
given me so far!!
Regards
kevin -
I am getting followong error
XML Parsing Error: undefined entity
Location: chrome://weave/content/options.xul
Line Number 6, Column 3: <setting id="weave-account" type="string" title="&account.label;" />
--^I had this problem - it appeared to be due to having Firefox 4 with the Firefox Sync installed as an add-on. Firefox 4 has sync included so there is no need to have it as an add-on. I went to the add-on manager and removed Firefox Sync and now appears to be working correctly.
-
I'm having trouble adding an additional account to FireFTP. I keep getting a yellow box with this title:
XML Parsing Error: undefined entity
Location: chrome://fireftp/content/accountManager.xul
Line Number 216, Column 17:
<menu label="&charsetMenuMore1.label;" accesskey="&charsetMenuMore1.accesskey;" datasources="rdf:charset-menu" ref="NC:BrowserMore1CharsetMenuRoot">
----------------^
Don't understand the problem, can anyone help please?Try updating FireFTP to the latest 2.0.20 version.
''An update for Firefox 32 compatibility.''
https://addons.mozilla.org/en-US/firefox/addon/fireftp/ -
Unable to use variables of a function module in am enhancement spot
Hi All,
I have created an implicit code enhancement spot at the end of a function module. In this enhancement I am unable to access the local variables and the import/export variables of the function module. Is this the expected behavior or I am doing something wrong.
Thansk & Regards,
SaurabhHi Saurabh,
Can you explain your scenario in detail with tcode and function module and all.
Regards,
kamalapriya -
Substitution variable in the functions
Can we call substitution variable in the functions in essbase calc scripts
for example fix (@IRSIBLINGS(&mois_en_cours_reprev));Sould be just fine. Does it validate? If not, make sure the variable is spelled correctly in EAS (always start with the easy solution first :) ).
-
How can I transfer a variable to regexp_replace function
Hi,
In addition to my question from yesterday, I went up one (little) level for the next question.
How can I transfer a variable to regexp_replace function?
I am getting the value of the variables from from APEX Items.
The value of item :P105_OLD_NAME should be replaced with the value from :P105_NAME APEX item.
The projects in PROJECT_NAME field are separated by “:”
select * from infoux_proj;
HOSTNAME PROJECT_NAME
host1 proj2:proj1
host3 proj1
host4 proj12:proj1
host5 proj3
host2 proj1:proj3:sunproj1
this is my code:
declare
v_old_proj_list varchar(100);
v_new_proj_list varchar(100);
begin
for host in (select a.hostname, project_name
from infoux_proj a,
(select hostname
from PROJECT_NAMES_WITH_HOSTNAMES
where name = :P105_OLD_NAME ) b
where a.HOSTNAME=b.hostname)
loop
select project_name ,
regexp_replace(project_name,'(^|:)(:P105_OLD_NAME)(:|$)','\1:P105_NAME \3') new_project
into v_old_proj_list, v_new_proj_list
from infoux_proj
where hostname=host.hostname;
update infoux_proj
set project_name=v_new_proj_list
where hostname=host.hostname;
end loop;
end;
Thanks,
SheliHi, Sheli
Inside quotes, :p105_old_name will not be taken as a variable name. If you want to use the value of :p105_old_name in a string which its otherwise a literal, then you can concatenate the variable to the literal parts, using the || operator.
You can do soemthing like this:
REGEXP_REPLACE ( project_name
, '(^|:)(' || :P105_OLD_NAME
|| ')(:|$)'
, '\1' || :P105_NAME
|| ' \3'
) AS new_projectI'll bet there's a much simpler way to do what you want. Instead of having two SELECTs, a cursor FOR loop and an UPDATE, you can probably do what you need to with just a single UPDATE or MERGE. It would be more efficient, too. If you'd like help, post CREATE TABLE and INSERT statements for all relevant tables and columns azs the exist before this code is run, a couple of sets of values for the bind variables, and the results you'd like to see (that is, the contents of the changed table) for each set, given the same sample data.
Always say which version of Oracle you're using. -
How to use session variable in JSP function & How to use both JSP Servlet
Hi,
I am new to JSP and servlets
Still I am devloping a website in JSP. I am not mixing JSP with servlets, but I do create Java files for bean, logic and database works.
I try to keep the hard coding part out of JSP.
I dont how to use both JSP and Servlets in combination.
Hence If needed I write some functions in JSP.
but it gives me error
+<%! public void abc()+
+{+
int intUserId = Integer.valueOf((Integer) session.getAttribute("MySession_UserID"));
+}+
+%>+
Saying cannot find symbol session
1) So can u please tell how can I access session variables within JSP function
2) And also give me some links/tutorials about useing both JSP and Servlets in combination.
Thanks
VenkatThe application architecture when you use Servlets and JSP in a standard MVC pattern is explained here (under the heading "Integrating Servlets and JSP Pages") and here ...
-
Using a global variable within a function
Hi all,
I'm trying to learn how to use global variables, but can't quite get it right:
Im trying to use two buttons, named UpButton and DownButton to control one global variable, p1
A text field, named "Value" displays p1.
Here's my code:
p1 = 0;
ButtonClick("UpButton", p1, 100,"Value");
ButtonClick("DownButton", p1,(-100),"Value");
function ButtonClick(ButtonName,Var,Increment,TextToChange){
sym.$(ButtonName).click(function(){
Var = Var + Increment;
sym.$(TextToChange).html(Var);
However, it seems to be treating p1 as two different variables.
Here's a link to the page to show you what I mean, apologies but this link wont work in google chrome because I'm using dropbox as a server temporarily
In other browsers you may need to click "Show all content" or similar to any security warnings...
https://dl.dropboxusercontent.com/u/83693404/ButtonTest/buttons.html
Here are the project files:
https://app.box.com/s/0shocivto8fl295h62uq
Any help greatly appreciated, sorry if this is a stupid question,
KatherineHi Katherine,
However, it seems to be treating p1 as two different variables.
Indeed, your code created two different variables in two different scopes (I guess it as to do with JavaScript closures, but do not ask me more, I am still a bit foggy about that idiosyncrasy ).
In JavaScript, a primitive parameter – this is the case here with p1, a Number value –, is passed by value. In other words, a copy of the value is made. Your code handles two copies of the value stored in p1.
This contrasts with an object parameter, which is passed by reference (address in memory), without copy. Your code would work if Numbers were passed by reference : the two Var (p1) would then point to the same address.
The intent behind your trial is a global variable.
1) Let us be as simple as possible :
Stage : document.compositionReady event handler
p1 = 0;
buttonClick = function( Increment)
p1 += Increment;
sym.$( "Value").html( p1);
Stage : DownButton.click event handler
buttonClick(-100);
Stage : UpButton.click event handler
buttonClick(100);
Without being preceded by the var keyword the variables are global.
So the Number variable p1 can be accessed inside function buttonClick.
And the Function variable buttonClick as well, is accessible inside click event handlers, everything (function definition +function calls) being inside the same symbol (Stage).
2) Now, suppose this is no longer the case : you want to access a variable from another symbol.
We create a new GraySquare symbol, instantiated both in the DownButton symbol (instance name DownSquare) and in the UpButton symbol (instance name DownSquare).
Stage : document.compositionReady event handler
p1 = 0;
sym.buttonClick = function( Increment)
p1 += Increment;
sym.$( "Value").html( p1);
The sym. prefix is now necessary to make the variable (here a Function, but you would proceed exactly the same with a String, Number or Boolean) accessible in other symbols.
DownButton symbol : DownSquare.click event handler
sym.getComposition().getStage().buttonClick( -100);
UpButton symbol : UpSquare.click event handler
sym.getComposition().getStage().buttonClick( 100);
From these other symbols, the sym.getComposition().getStage(). prefix is necessary to acces to our global variable (function).
The two examples are downloadable here : https://app.box.com/s/6vkyiqk7i8zwlw0j1wk1
Gil -
The full error message is the following:
XML Parsing Error: Undefined entity
Location chrome://mozapps/content/downloads/unknown content type.xul
Line Number 30, Column 18In order to use ''nxm://'' links, Nexus Mod Manager must be installed and associated with the ''nxm'' protocol.
* http://www.nexusmods.com/skyrim/mods/modmanager/
In case of problems with this third-party program, please refer to its support forum:
* http://forums.nexusmods.com/index.php?/forum/1413-nmm-code-development-chat
Maybe you are looking for
-
How do I use a thermocoup​le with a SCB 68
My system consists of a PCI-6024E card SCB 68 and Labview 7. I want to connect a T type thermocouple to the SCB box and measure (hopefully) an ambient temperature. I have tried connecting to channel 0 in differential and single ended mode and have ch
-
I'm unable to open up Lightroom 5, I get this message in a pop up box: "Lightroom encountered an error when reading from it's preview cache and needs to quit" Underneath that is "Lightroom will attempt to fix this problem the next time when it launc
-
How can I Add/Change Icon's for Bookmarks in Bookmarks toolbar?
My bookmarks toolbar at the moment has several links in it, most with just the icon(such as the YouTube logo). But some won't come up with icons, so I have to put a name next to it. I was wondering how I would go about adding an Icon there, so I can
-
How can i sync my new phone to my itunes without loosing everything? ive got a iphone 3gs at the moment and getting a 3gs tomorrow ive been told if i sync my new iphone with itunes ill loose everything!
-
I would just like to say that I believe this board would be awesome if it had a section for Verizon customers to give Verizon input on what they would like to see in the future. I mean come on I have been a Verizon customer for as long as I can remem