Flashserver and multiple arguments.

Aug 2, 2008 at 7:58pm

Flashserver and multiple arguments.

I’d like to control two independent movie clips from MaxMSP to Flash (if possible). I’ve managed to get one working which moves a movie clip along the x axis like so:

function onMaxData(doc)
{
argv = []; // create a new array
doc = doc.substr(0, doc.length – 1); // chop off ‘;’ at the end
argv = doc.split(” “); // split at spaces and convert to array
argc = argv.length; // get number of elements in array
for(i = 0; i < argc; i++) // loop through all arguments

clip = argv[0]; // get name of MovieClip
axisx = argv[1]; // get the frame number
_root[clip]._x = axisx;

clip1 = argv[2];
alpha1 = argv[3];
_root[clip1]._alpha = alpha1;
}

However, I assumed by adding the last three lines of code I could manipulate the alpha of an independent (second) movie clip. But no, whatever value I enter into max will just change the x value of the second movie clip. Does anyone have any hints as how to direct this additional input stream so it changes just alpha of the secondary clip?

I might point also out that both clips work independently. I have these two messages in Max:

send 1 crosshair 340 – manipulates x-axis value of 1st movie clip
send 1 c2 100 – i would like this to manipulate alpha of second movie clip (but it doesn’t).

#39104
Aug 2, 2008 at 8:25pm

Chris wrote:
> I’d like to control two independent movie clips from MaxMSP to Flash (if possible). I’ve managed to get one working which moves a movie clip along the x axis like so:
>
> function onMaxData(doc)
> {
> argv = []; // create a new array
> doc = doc.substr(0, doc.length – 1); // chop off ‘;’ at the end
> argv = doc.split(” “); // split at spaces and convert to array
> argc = argv.length; // get number of elements in array
> for(i = 0; i < argc; i++) // loop through all arguments
>
> clip = argv[0]; // get name of MovieClip
> axisx = argv[1]; // get the frame number
> _root[clip]._x = axisx;
>
> clip1 = argv[2];
> alpha1 = argv[3];
> _root[clip1]._alpha = alpha1;
> }
>
> However, I assumed by adding the last three lines of code I could manipulate the alpha of an independent (second) movie clip. But no, whatever value I enter into max will just change the x value of the second movie clip. Does anyone have any hints as how to direct this additional input stream so it changes just alpha of the secondary clip?
>
> I might point also out that both clips work independently. I have these two messages in Max:
>
> send 1 crosshair 340 – manipulates x-axis value of 1st movie clip
> send 1 c2 100 – i would like this to manipulate alpha of second movie clip (but it doesn’t).

Of course not. (BTW, this is a Flash ActionScript question you should
post on a forum dedicated to that.) Anyway:

You send two different commands, so Flash has to decide which is which
when it receives something. The first argument is what tells Flash what
the following data is supposed to mean. So try this:

argv = []; // create a new array
doc = doc.substr(0, doc.length – 1); // chop off ‘;’ at the end
argv = doc.split(” “); // split at spaces and convert to array

So far we have converted the string we received into an array of
elements argv[0] up to argv[x] (with x = argv.length – 1).

Now we can look at the first element which is in argv[0]. If this equals
“crosshair” then you know it’s the first massege you sent and thus in
argv[1] (i.e. next element in the array) you will find the value 340.

In case argv[0] was “c2″ then it’s the other message.

So do something like this (untested):

if (argv[0] == ‘crosshair’)
{
crosshair = parseInt(argv[1]);
}
else if (argv[0] == ‘c2′)
{
c2 = parseInt(argv[1]);
}

You don’t need the for() loop.

Olaf

#137242
Aug 2, 2008 at 9:22pm

Many thanks Olaf. I have implemented your code as follows:

if (argv[0] == ‘crosshair’){
_root.crosshair._x = parseInt(argv[1]);
}

else if (argv[0] == ‘c2′){
_root.c2._alpha = parseInt(argv[1]);
}

and it works spot on!

Although I appreciate this was an AS query, I thought here would be ok. However, I do not wish to dilute the forum with unrelated nonsense!

#137243

You must be logged in to reply to this topic.