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!

set actionscript variable with javascript 1

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
US
Hello --

I have some actionscript in my flash5 movie as follows:
Code:
var inputArray = new Array(2, 5);
var xArray = new Array(5);
var yArray = new Array(5);
var point0, point1, point2, point3, point4;
yArray[0] = 200-point0;
yArray[1] = 200-point1;
yArray[2] = 200-point2;
yArray[3] = 200-point3;
yArray[4] = 200-point4;
xArray[0] = 73;
xArray[1] = 110;
xArray[2] = 148;
xArray[3] = 185;
xArray[4] = 223;
setProperty ("point0", _y, yArray[0]);
setProperty ("point1", _y, yArray[1]);
setProperty ("point2", _y, yArray[2]);
setProperty ("point3", _y, yArray[3]);
setProperty ("point4", _y, yArray[4]);
for (i=0; i<4; i++) {
	drawLine(xArray[i], yArray[i], xArray[i+1], yArray[i+1], i);
}
function drawLine (x1, y1, x2, y2, index) {
	eval(&quot;line&quot;+index)._x = x1;
	eval(&quot;line&quot;+index)._y = y1;
	eval(&quot;line&quot;+index)._xscale = x2-x1;
	eval(&quot;line&quot;+index)._yscale = y2-y1;
}

I'm trying to set the 'point' variables with the following javascript on the html page:
Code:
function loadIt(){
	document.theGraph.SetVariable(&quot;point0&quot;, 25);
	document.theGraph.SetVariable(&quot;point1&quot;, 50);
	document.theGraph.SetVariable(&quot;point2&quot;, 75);
	document.theGraph.SetVariable(&quot;point3&quot;, 100);
	document.theGraph.SetVariable(&quot;point4&quot;, 75);
}

If I set the variables inside the movie, then it works perfectly, but I can't seem to get the variables to send into Flash.

I had figured out a solution to this type of problem in Flash4 a while back, but I'm guessing the method has changed from 4 --> 5??

Any help greatly appreciated.

paul
penny.gif
penny.gif
 
hi link, have a look at the sectyion of your html code containing the flash plugin. Make sure that the name of the flash object is defined for between both the <OBJECT> tags and the <EMBED> tags. ie: if the name of your swf is &quot;theGraph.swf&quot; then you could insert name=&quot;theGraph&quot; betwenn both the sets of tags (although the name you select can be anything).

Now, anywhere in the <body> section after the Flash plug-in code, insert the following:

Code:
<SCRIPT LANGUAGE=JavaScript>
document.theGraph.SetVariable(&quot;point0&quot;, 25);
document.theGraph.SetVariable(&quot;point1&quot;, 50);
document.theGraph.SetVariable(&quot;point2&quot;, 75);
document.theGraph.SetVariable(&quot;point3&quot;, 100);
document.theGraph.SetVariable(&quot;point4&quot;, 75);
</SCRIPT>

For those who don't know, this puts 5 variables onto the main timeline of the Flash movie automatically, they are:

point0=25
point1=50
point2=75
point3=100
point4=25

If you were defining a string variable you would put the value in quotes, thus:
Code:
document.theGraph.SetVariable(&quot;point4&quot;, &quot;dave&quot;);

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Thanks Dave.

I wonder if you (or anyone else. I'm not picky ;-)) know the ins and outs of how NS refers to the movie object.

document.theGraph.setVariable(...)

is now working great for IE, but not for NS.

I have tried

window.theGraph.setVariable(...)

to no avail.

Any ideas?

Thanks -
paul
penny.gif
penny.gif
 
Here's the client side script I'm using to talk to the movie. Works perfectly in IE (of course), but not for NS(of course). Thanks greatly for any insight.

Code:
<script language=javascript>
function movieobject(moviename)
{
//IE and Netscape refer to the movie object differently.
//This function returns the appropriate syntax depending on the browser.

	if (navigator.appName.indexOf (&quot;Microsoft&quot;) !=-1) 
	{
		return window[moviename]
	}

	else
	{
		return document[moviename]
	}
}
function loadIt(){
	var moviename = 'theGraph';
	movieobject(moviename).SetVariable(&quot;graph1&quot;, 0);
	movieobject(moviename).SetVariable(&quot;graph2&quot;, 75);
	movieobject(moviename).SetVariable(&quot;graph3&quot;, 50);
	movieobject(moviename).SetVariable(&quot;graph4&quot;, 195);
	movieobject(moviename).SetVariable(&quot;graph5&quot;, 125);
}
</script>
penny.gif
penny.gif
 
following code works, both browsers:

Code:
<HTML>
<HEAD>


<script language=javascript>
function movieobject(moviename)
{
//IE and Netscape refer to the movie object differently.
//This function returns the appropriate syntax depending on the browser.

    if (navigator.appName.indexOf (&quot;Microsoft&quot;) !=-1) 
    {
        return window[moviename]
    }

    else
    {
        return document[moviename]
    }
}
function loadIt(){
    var moviename = 'theGraph';
    movieobject(moviename).SetVariable(&quot;point0&quot;, 0);
    movieobject(moviename).SetVariable(&quot;point1&quot;, 75);
    movieobject(moviename).SetVariable(&quot;point2&quot;, 50);
    movieobject(moviename).SetVariable(&quot;point3&quot;, 195);
    movieobject(moviename).SetVariable(&quot;point4&quot;, 125);
}
</script>


<TITLE>theGraph</TITLE>
</HEAD>
<BODY bgcolor=&quot;#FFFFFF&quot;>
<!-- URL's used in the movie-->
<!-- text used in the movie-->
<OBJECT classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;
 codebase=&quot;[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0&quot;[/URL]
 WIDTH=600 HEIGHT=300 ID=&quot;theGraph&quot;>
 <PARAM NAME=&quot;movie&quot; VALUE=&quot;theGraph.swf&quot;> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED NAME=&quot;theGraph&quot; src=&quot;theGraph.swf&quot; quality=high bgcolor=#FFFFFF  WIDTH=600 HEIGHT=300  TYPE=&quot;application/x-shockwave-flash&quot; PLUGINSPAGE=&quot;[URL unfurl="true"]http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash&quot;></EMBED>[/URL]
</OBJECT>


<SCRIPT LANGUAGE=JavaScript>
document.theGraph.SetVariable(&quot;point0&quot;, 25);
document.theGraph.SetVariable(&quot;point1&quot;, 50);
document.theGraph.SetVariable(&quot;point2&quot;, 75);
document.theGraph.SetVariable(&quot;point3&quot;, 100);
document.theGraph.SetVariable(&quot;point4&quot;, 75);
</SCRIPT>


</BODY>
</HTML>

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
NS6.2


Still doesn't work, my friend. The .swf is in that same dir called paulCavan.swf, not that you need it, since there's no question there's nothing wrong w/ the flash file. It's the communication to the .swf w/ NS that is the issue.

Now, I had read before that NS and IE refer to the movie object differently, which is why I had that movieObject() function that returned the different references depending on browser. In your solution, you completely bypassed that function.

Your solution works just fine in IE, as it did when I was calling loadIt() onLoad for the body tag like so:

<body onLoad=&quot;loadIt();&quot;>

You can play with that if you feel the desire.

Anyway, I'm going to keep banging my head on the monitor. Let me know if you come up with anything.

Thanks :)
paul
penny.gif
penny.gif
 
in the first message you posted, you defined the variables as &quot;point&quot; but then later as &quot;graph&quot;, could it just be that the variables being sent are wrong? The above html source works cross-browser for definite, the swf file which I made for the page just contains five dynamic text boxes named point0, point1, etc. No problems at all.

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
No, I did rename the variables in the movie in my quest for a bit cleaner code.

Are you telling me that if you click on the link I have provided up there, it works in both IE and NS???

If I click on that link w/ IE, it works. If I click on it with NS, it doesn't work.

What you should see is a little graph with points of varying heights on it. In NS, they're all sitting directly on the x axis in my browser.

If you would check it for me just to satisfy my curiosity.

lemme know -
paul
penny.gif
penny.gif
 
works in both for me paul
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Please don't tell me I'm SOL for this method on NS6.

I read that page you posted (and thanks), but surely there must be some way to work it.

:-(
penny.gif
penny.gif
 
MUST you use javascript to pass the variables? Couldn't you load from a txt file or ASP script?
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Well, if you are versed in how to communicate w/ Flash w/ ASP, I'd love to hear it.

What I had planned on doing, since I was under the impression you had to have a go-between for ASP & Flash, was to dynamically create the javascript with ASP to create my graphs. That way, one .swf and one .asp file creates an infinite number of graphs that are different each time you call on them, depending on what values I pull from my database (user choices).

Using a text file is somewhat of an option, but I'll have to work out the logistics on it, since this will be a multi user site and many ppl will hit it at the same time, and many graphs will have to be rendered to any single user at one time, too.

I can create and delete txt files w/ASP, but I was afraid of the server load, or worse yet, trying to create the same file at the same time, since I assume that the file will have to be called the same thing each time in order for flash to read from it. Actually, now that I think about it, txt files won't really be an option. I'd have to create a hundred .swf files and make each one read from a different txt file, and the txt files would have to be created and deleted each time a user requested a graph. Too much overhead for an efficient application.

So back to the ASP... do you know how I can communicate directly w/ Flash using ASP? I'm all ears.

Thanks -
paul
penny.gif
penny.gif
 
hmmm, I actually stick to PHP these days, I stumbled over ASP last year and kinda just left it lying.

Any chance you could use PHP because I've literally spent that past two days doing exactly what you need. For my drawing app, the user draws the lines, these are then sent via PHP to a mySQL database where they can be recalled at a later date in a kind of gallery. The swf which recreates the selected picture is the same for everyone, as is the PHP file which pulls the relevant data from the database and back to the swf file for recreation of their picture.

You can definitely use ASP/Flash and an MSAccess database together, but's it's been a loooong time since i made anything.
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
not of my own creation I must say, taken from the CD of a book called Server Side Flash.

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 

uses the same database from previous zip. Probably more suited to your cause because it sends the data back in array form, so you could set it up to show a specific record.

BTW, my reasoning behind sending you these is that you will be able to write your graph information in the database in array form, and instead of name/email information you would have graphname/graphdata. your data would simply be written into the graphdata(email) field in the form 25,30,30,50,10 and when the ASP script sends you that back, all you have to do is utilise the array.split(&quot;,&quot;) command to extract the coordinates.

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Dave, I appreciate your help.

I have to say I'm a bit discouraged. This particular application is a customer satisfaction survey database that is around 20k records (and that grows by that number each quarter). Problem is that I can't just store the variables I need to use... dynamic SQL statements are built in my ASP (only, sorry to say) scripts, and then passed to a SQL Server database, where it returns the performance scores. So, while not truly infinite, there are an inordinate amount of possible values that these graphs might have to take on.

I am downloading your example right now, and I'll take a look to see if I can make it work for me.

Again, thanks alot for your advice.

:)
paul
penny.gif
penny.gif
 
After a bit more head banging, I have come to terms that this site is not a &quot;flash&quot; site, and since my client absolutely refuses to use the FAR superior browser that already ships w/ their OS, I have decided to deliver to them an inferior product at the same price.

Dynamic HTML bar graphs it is.

Ah well.

Thanks again, my friend.

:)
paul
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top