Skip to main content
July 24, 2007
Question

XML and AS2.0

  • July 24, 2007
  • 21 replies
  • 1270 views
OK I have been going down one road for this and have taken a few wrong turns.

A few things about what we are looking at:
I am using Flash CS3 but I am using Action Script 1.0/2.0 for compatability purposes.

What I have been able to do so far is create random instances of a movie clip to appear over a set amount of time but I need to go a bit further. The web application needs to be updated regularly and the best way I can think of doing that is with keeping all the variables in an XML. The problem is I am not sure how to format the XML properly to get Flash to read it and load the variables.

I am creating an online version of a vision screening tool we use. The test is graphically simple just a collection of a few primitives on a dark background. There are basically two objects a fixation point and a stimulus. What I need to be able to do is this.

Display either movieclip at (x,y) for (z)ms where x,y,& z are all variables loaded from an xml. I have asked questions along this line before but this is a different scope in case anyone wants to claim I double posted, this is quite different than they way I was doing it before.

Any help with the XML or even any actionscript suggestions would be greatly appreciated.

Thanks
This topic has been closed for replies.

21 replies

Inspiring
July 26, 2007
Okay, that looks good. So, in this case _root and _level0 are the same
thing (this isn't always the case but here it is).

So, the only two things I can see, as per my previous post, are:

1. Your enterFrame loop is hard-setting the position. Whatever you set
it to outside of this, this loop simply resets it next time the frame
loop hits. So...comment it out or get rid of it.

2. Your X and Y values may not be numbers. You should try something like:

_root[ovalue]=Number(xValue);
_root[ovalue]=Number(yValue);

If they are numbers, no problem. If they're not, this should convert it.
Like I said, this is a 2-inch view of the whole canvas so this is the
best I can do without seeing everything you've written.

Good luck!

Patrick

shurleynova wrote:
> Ok I see your point, I commented out the other trace statements and only left
> the following two trace statements
>
> trace ('Data loaded: '+success);
> and
> trace (_root[oValue]);
>
> and the output file now looks like this:
>
> Data loaded: true
> _level0.stimuli
> _level0.stimuli
> _level0.stimuli
> _level0.stimuli
> _level0.fixation
>
> so it looks like it is grabbing the right variable from the XML
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
July 26, 2007
Ok I see your point, I commented out the other trace statements and only left the following two trace statements

trace ('Data loaded: '+success);
and
trace (_root[oValue]);

and the output file now looks like this:

Data loaded: true
_level0.stimuli
_level0.stimuli
_level0.stimuli
_level0.stimuli
_level0.fixation

so it looks like it is grabbing the right variable from the XML
Inspiring
July 26, 2007
Okay...I'm not sure how you came up with that but assuming you're
right...first...are the values you're trying to set numbers? They may
*look* like numbers but if they're strings, the X and Y position won't
be affected.

_root[ovalue]._x=Number(xValue);
_root[ovalue]._y=Number(yValue);


Second, do you still have this?

onClipEvent (enterFrame) {
setProperty(_root.stimuli,_x,55);
setProperty(_root.stimuli,_y,115);

}

This continually loops and sets the clip X and Y to 55,115 so get rid of
it. It sounds like you're making a bit of a dog's breakfast of your code
because you're trying to fix things piecemeal.

At this point you may have 2 or 3 things that are working against each
other. I only see the tiny bits of code you are posting here and not
seeing it in context. If you were to ask me what could be causing the
clips not to go to their target position, the answer is literally
"anything". It certainly sounds like you're not sure how to set X and Y
position or how to correctly work with values but how many other
problems do you have in your code that could be causing this? I've seen
one onEnterFrame loop and I've suggested an XML parsing routine that's
out of context (it's very generic and not suited to what you're doing
specifically...whatever that is). I would advise that you either read up
on core Flash concepts like movie clip references, scope, setting
properties, and looping...or you post your code in its entirety so I can
give you a rundown how the pieces fit together. It's very difficult to
work with bits and pieces when other bits and pieces may the crucial
problems.

Feel free to drop me an email if you want and we can continue this off
the forums.

Patrick


shurleynova wrote:
> So I guess the short answer to that question is it is a movieclip
>
> the movieclip is named "mc_stimuli" and has an instance name "stimuli" and its
> path is simply "_root.stimuli" or "_level0.stimuli" which appear to be one in
> the same.
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
Inspiring
July 26, 2007
Woaw....when your trace _root[ovalue] you get all that? This doesn't
look right at all. If this was a complex object, you should see "[object
Object]", if it's a movie clip you should see "[object MovieClip]" or
the path to the movie clip.

What I'm seeing here looks like many trace statements. Did you remove
the ones from the "for" loop? If you leave all the other ones in there,
what you end up with is meaningless because any one of thos lines may or
may not be what we want to see. We're trying to isolate one value
here...you're showing me everything you're receiving plus some other
data without any context. Get rid of all your trace statements and,
leaving only the one, ....what does trace(_root[ovalue]); show you?
Don't put it in a loop. We want only one line of text. If you get more
than that, check your code again and remove any remaining traces.


shurleynova wrote:
> when I trace using trace (_root[oValue]);
>
> my output is:
>
> Data loaded: true
> object_type=stimuli
> x_coordinates=25
> y_coordinates=25
> z_display_interval=200
> _level0.stimuli
> object_type=stimuli
> x_coordinates=85
> y_coordinates=175
> z_display_interval=200
> _level0.stimuli
> object_type=stimuli
> x_coordinates=325
> y_coordinates=55
> z_display_interval=200
> _level0.stimuli
> object_type=stimuli
> x_coordinates=115
> y_coordinates=355
> z_display_interval=200
> _level0.stimuli
> object_type=fixation
> x_coordinates=289
> y_coordinates=229
> z_display_interval=200
> _level0.fixation
>
> --
> is _level0 and _root the same thing?
>
> because if I add the action to the clip
>
> onClipEvent (enterFrame) {
> _level0.stimuli._x=55;
> _level0.stimuli._y=55;
>
> }
>
> or
>
> onClipEvent (enterFrame) {
> _root.stimuli._x=55;
> _root.stimuli._y=55;
>
> }
>
> the results are the same the movieclip with the instance name 'stimuli'
> appears at (x,y) 55,55. So my guess is even though the variables are loaded
> and the trace shows me they are the onClipEvent doesn't see it that way.
> Logically the action script
>
> onClipEvent (enterFrame) {
> _root.[oValue]._x=55;
> _root.[oValue]._y=55;
>
> }
>
> should have the same effect but it doesn't that is kinda why I am confused.
> If the variables are loaded and the code works with hardcoded data why does
> replacing the hard coded information with the variable not work.
>
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
July 26, 2007
So I guess the short answer to that question is it is a movieclip

the movieclip is named "mc_stimuli" and has an instance name "stimuli" and its path is simply "_root.stimuli" or "_level0.stimuli" which appear to be one in the same.
July 26, 2007
when I trace using trace (_root[oValue]);

my output is:

Data loaded: true
object_type=stimuli
x_coordinates=25
y_coordinates=25
z_display_interval=200
_level0.stimuli
object_type=stimuli
x_coordinates=85
y_coordinates=175
z_display_interval=200
_level0.stimuli
object_type=stimuli
x_coordinates=325
y_coordinates=55
z_display_interval=200
_level0.stimuli
object_type=stimuli
x_coordinates=115
y_coordinates=355
z_display_interval=200
_level0.stimuli
object_type=fixation
x_coordinates=289
y_coordinates=229
z_display_interval=200
_level0.fixation

--
is _level0 and _root the same thing?

because if I add the action to the clip

onClipEvent (enterFrame) {
_level0.stimuli._x=55;
_level0.stimuli._y=55;

}

or

onClipEvent (enterFrame) {
_root.stimuli._x=55;
_root.stimuli._y=55;

}

the results are the same the movieclip with the instance name 'stimuli' appears at (x,y) 55,55. So my guess is even though the variables are loaded and the trace shows me they are the onClipEvent doesn't see it that way. Logically the action script

onClipEvent (enterFrame) {
_root.[oValue]._x=55;
_root.[oValue]._y=55;

}

should have the same effect but it doesn't that is kinda why I am confused. If the variables are loaded and the code works with hardcoded data why does replacing the hard coded information with the variable not work.
Inspiring
July 25, 2007
If you put this on the frame within the clip itself (rather than on the
clip), you could use:

this.onEnterFrame=function() {
_root[ovalue]._x=xValue;
_root[ovalue]._y=yValue;
}

But maybe that's something you can implement when you get the initial
problem fixed.

Patrick

Patrick B wrote:
> Your notation is a bit archaic but we can work with it :)
>
> onClipEvent (enterFrame) {
> setProperty(_root[oValue],_x,xValue);
> setProperty(_root[oValue],_y,yValue);
>
> }
>
> Better still:
>
> onClipEvent (enterFrame) {
> _root[oValue]._x=xValue;
> _root[oValue]._y=yValue;
>
> }
>
> Just make sure xValue and yValue exist and are numbers and you should be
> okay. How does that work out?
>
> Patrick
>
>
> shurleynova wrote:
>> Maybe this makes more sense
>>
>> if I have the following action script on a movieclip
>>
>> onClipEvent (enterFrame) {
>> setProperty(_root.stimuli,_x,55);
>> setProperty(_root.stimuli,_y,115);
>>
>> }
>>
>> The instance "stimuli" appears at 55,115 on my stage
>>
>> what I want to do is replace the instance name, the x and y
>> coodinates with the variables that I loaded from the XML.
>>
>> for some reason I thought it would be as simple as
>>
>> onClipEvent (enterFrame) {
>> setProperty(oValue,_x,xValue);
>> setProperty(oValue,_y,yValue);
>>
>> }
>>
>> but that, while not giving me an error , does nothing I can still see
>> the clip sitting in the position I placed it in to start.
>>
>> So my thought is my error is in the syntax of the script.
>>
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
July 25, 2007
quote:

Originally posted by: Newsgroup User
If you put this on the frame within the clip itself (rather than on the
clip), you could use:

this.onEnterFrame=function() {
_root[ovalue]._x=xValue;
_root[ovalue]._y=yValue;
}

But maybe that's something you can implement when you get the initial
problem fixed.

Patrick

Patrick B wrote:
> Your notation is a bit archaic but we can work with it :)
>
> onClipEvent (enterFrame) {
> setProperty(_root[oValue],_x,xValue);
> setProperty(_root[oValue],_y,yValue);
>
> }
>
> Better still:
>
> onClipEvent (enterFrame) {
> _root[oValue]._x=xValue;
> _root[oValue]._y=yValue;
>
> }
>
> Just make sure xValue and yValue exist and are numbers and you should be
> okay. How does that work out?
>
> Patrick
>
>



Ok I know my syntax is a bit rusty but I am slowly learning to appreciate the dot notation as a much easier way to read the code.

so I went ahead and place this code on a movie clip

onClipEvent (enterFrame) {
_root[oValue]._x=xValue;
_root[oValue]._y=yValue;

}

I checked the output window and the action script to make sure the xValue and yValue were being read as numbers and that it refelcted that in the output I have attached the action script below. Also this is what is in the output window:

Data loaded: true
object_type=stimuli
x_coordinates=25
y_coordinates=25
z_display_interval=200
object_type=stimuli
x_coordinates=85
y_coordinates=175
z_display_interval=200
object_type=stimuli
x_coordinates=325
y_coordinates=55
z_display_interval=200
object_type=stimuli
x_coordinates=115
y_coordinates=355
z_display_interval=200
object_type=fixation
x_coordinates=289
y_coordinates=229
z_display_interval=200

Maybe I am looking at this wrong and maybe there is one other step I need to include is what I keep thinking but I dont knwo what it is.


Inspiring
July 25, 2007
Your notation is a bit archaic but we can work with it :)

onClipEvent (enterFrame) {
setProperty(_root[oValue],_x,xValue);
setProperty(_root[oValue],_y,yValue);

}

Better still:

onClipEvent (enterFrame) {
_root[oValue]._x=xValue;
_root[oValue]._y=yValue;

}

Just make sure xValue and yValue exist and are numbers and you should be
okay. How does that work out?

Patrick


shurleynova wrote:
> Maybe this makes more sense
>
> if I have the following action script on a movieclip
>
> onClipEvent (enterFrame) {
> setProperty(_root.stimuli,_x,55);
> setProperty(_root.stimuli,_y,115);
>
> }
>
> The instance "stimuli" appears at 55,115 on my stage
>
> what I want to do is replace the instance name, the x and y coodinates with
> the variables that I loaded from the XML.
>
> for some reason I thought it would be as simple as
>
> onClipEvent (enterFrame) {
> setProperty(oValue,_x,xValue);
> setProperty(oValue,_y,yValue);
>
> }
>
> but that, while not giving me an error , does nothing I can still see the clip
> sitting in the position I placed it in to start.
>
> So my thought is my error is in the syntax of the script.
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
July 25, 2007
Maybe this makes more sense

if I have the following action script on a movieclip

onClipEvent (enterFrame) {
setProperty(_root.stimuli,_x,55);
setProperty(_root.stimuli,_y,115);

}

The instance "stimuli" appears at 55,115 on my stage

what I want to do is replace the instance name, the x and y coodinates with the variables that I loaded from the XML.

for some reason I thought it would be as simple as

onClipEvent (enterFrame) {
setProperty(oValue,_x,xValue);
setProperty(oValue,_y,yValue);

}

but that, while not giving me an error , does nothing I can still see the clip sitting in the position I placed it in to start.

So my thought is my error is in the syntax of the script.
Inspiring
July 25, 2007
Hi again,

I'm still a little fuzzy on what you're trying to do. Are you trying to
set the X and Y position of the clip? What is ovalue, or rather, what do
you want it to be? When you trace (ovalue), what do you get? What about
trace (typeof(ovalue))?

Patrick



shurleynova wrote:
> sort of
> the variables contain the x,y coordinates and the name of the movieClip
> instance as well as a value for a timer event. The last one is not the most
> important so lets just leave that out for the moment.
>
> I was trying to state it with a with statement as in:
>
> with(oValue){
> _x=xValue
> _y=yValue
> }
>
> but that is when I get the error that the object does not exist. Do I need to
> add some actionscript to my movieClip to make it work? Or is there another way
> to do it? Do I need to add an event to the clip itself I guess is what I am
> asking or do I need to attach the code that makes the clip appear the clip
> itself?
>
> I did already make sure that the clips were exported for Actionscript but that
> didnt seem to make a difference
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
July 25, 2007
Hello again,

"Are you trying to
set the X and Y position of the clip? What is ovalue, or rather, what do
you want it to be? When you trace (ovalue), what do you get? What about
trace (typeof(ovalue))?"

I am tracing the oValue and yes I am trying to set the x,y of the clip. The oValue is a variable that is either one of two things "stimuli" or "fixation" and when I trace it that is what is says in the output window. What the oValue is meant to represent is an instance name. but even something as simple as setProperty does not recognize the variable in place of the clip's instance name. So here I am thinking that it may not be possible to pass a variable to call an instance name but it doesn't make sense, because in theory I figure it should work.

thnx a million - your solutions have been the most helpful thus far.