Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Position of mc (x,y) based on external var

Status
Not open for further replies.

keish

Technical User
Apr 1, 2007
7
PT
Hi,

I'm kinda new in actionscript so I need your help on this. I'm trying to create a swf that gets vars (friend1;friend2;local1 and local2) from a txt file and insert it on the textboxs (instanced as box1_txt;box2_txt;local1_txt and local2_txt).

So far so good. I managed to do that with the folowing code:

myData = new LoadVars();
myData.onLoad = function(success){
if (success) {
box1_txt.htmlText = this.friend1;
box2_txt.htmlText = this.friend2;
local1_txt.htmlText = this.local1;
local2_txt.htmlText = this.local2;
}
}
else {
box1_txt.htmlText = "error loading variable";
box2_txt.htmlText = "error loading variable";
}
}
myData.load("example.txt");


But now I need to create 2 movieclips and its position (x,y) must change acording to the vars local1 and local2.
I must be doing something (completely) wrong. I tried to following code:


_root.circulo1_mc._visible = false;

if (local1_txt.htmlText == "Rome") {
circle_mc._visible = true;
circle_mc._x = 287.0;
circle_mc._y = 72.0;
}
else {
if (local1_txt.htmlText == "Sydney") {
circle_mc._visible = true;
circle_mc._x = 387.0;
circle_mc._y = 72.0;
}
else {


This code doesn't retrieve any error but it just doesn't work. I also tried to make the mc always visible but it's positions stays always the same.

Can someone help me with this?
Thx in advance.
 
i think the problem may be when you are running the code to move the movie clip

i would try placing it in a function and call that function form the onload

something like

myData.onLoad = function(success){
if (success) {
box1_txt.htmlText = this.friend1;
box2_txt.htmlText = this.friend2;
local1_txt.htmlText = this.local1;
local2_txt.htmlText = this.local2;
moveClip();
}
}
else {
box1_txt.htmlText = "error loading variable";
box2_txt.htmlText = "error loading variable";
}
}

function moveClip(){
if (local1_txt.htmlText == "Rome") {
circle_mc._visible = true;
circle_mc._x = 287.0;
circle_mc._y = 72.0;
}
else {
etc etc
}

 
Code:
myData = new LoadVars();
myData.onLoad = function(success) {
	if (success) {
		box1_txt.htmlText = this.friend1;
		box2_txt.htmlText = this.friend2;
		local1_txt.htmlText = this.local1;
		local2_txt.htmlText = this.local2;
		[b]circle_mc._y = 72;
		switch (this.local1) {
		case "Rome" :
			circle_mc._x = 287;
			break;
		case "Sydney" :
			circle_mc._x = 387;
			break;
		}[/b]
	} else {
		box1_txt.htmlText = "error loading variable";
		box2_txt.htmlText = "error loading variable";
	}
};
myData.load("example.txt");
stop();

Kenneth Kawamoto
 
Thank you guys for your quick help. Both codes seems right.

You're life savers ;). I really appreciate it.


Keish
 
I've tried to use the Kenneth code and it works fine but I still have a problem. I need to change both x and y coordinates, so I tried the following but nothing happened:

myData = new LoadVars();
myData.onLoad = function(success) {
if (success) {
box1_txt.htmlText = this.friend1;
box2_txt.htmlText = this.friend2;
local1_txt.htmlText = this.local1;
local2_txt.htmlText = this.local2;
switch (this.local1) {
case "Rome" :
circle_mc._x = 287;
circle_mc._y = 72;
break;
case "Sydney" :
circle_mc._x = 387;
circle_mc._y = 142;
break;
}
} else {
box1_txt.htmlText = "error loading variable";
box2_txt.htmlText = "error loading variable";
}
};
myData.load("example.txt");
stop();


Can u help me?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top