AS 1.0 Script, to AS 2.0 Scrirt

Do you use Script assist (aka V2 normal mode)? This is the forum for you.
Post Reply
mysg20
Posts: 4
Joined: Mon Jun 30, 2003 5:56 pm

AS 1.0 Script, to AS 2.0 Scrirt

Post by mysg20 » Tue Aug 02, 2005 12:34 pm

can anyone help me with this. I haven't been using flash for to long and need some help manipulating this code. I was told "you have to pass a String to 'parseInt()' " to make this work. Not sure how to do that.

here is the section AS this pertains to:

// volume
diff = Math.floor(_root.dragMC._x) - Math.floor(constL)
width = Math.floor(_root.const._width)
soundVol = parseInt((panDiff/panWidth)*100)
soundObj.setVolume(soundVol)
// pan
panDiff = Math.floor(_root.panDragMC._x) - Math.floor(constPanObjL)
panWidth = Math.floor(_root.constPan._width)
panVolume = parseInt((panDiff/panWidth)*200) - 100
panVolumeR = "R"+ (panVolume+100)
panVolumeL = "L"+ (100-panVolume)
soundObj.setPan(panVolume)

Devin
Posts: 15
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Post by Devin » Tue Aug 02, 2005 11:55 pm

I don't see anything wrong with this code other than the missing semicolons. parseInt will work with ActionScript 2.0. Are you saying this code works with ActionScript 1.0 but not 2.0?

mysg20
Posts: 4
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Post by mysg20 » Wed Aug 03, 2005 11:16 am

yes, it does not work with AS 2.0. Here is the full error that I get when I preview:

**Error** Scene=Scene 1, layer=Sripts, frame=2:Line 67: Type mismatch.
soundVol = parseInt((panDiff/panWidth)*100)

**Error** Scene=Scene 1, layer=Sripts, frame=2:Line 72: Type mismatch.
panVolume = parseInt((panDiff/panWidth)*200) - 100

Total ActionScript Errors: 2 Reported Errors: 2



I have been working on this for about a month and with no luck with getting it to work properly.

var_rich:SqueekyWheel
Posts: 7
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Post by var_rich:SqueekyWheel » Wed Aug 03, 2005 10:37 pm

Correct me if I'm wrong, but you are not trying to convert a string to an integer, so why use parseInt() at all.

It looks more like what your want is Math.round()

(panDiff/panWidth)*200 should give you a number to begin with. From my understanding parseInt() is not the same as an evaluate funtion. Depending how you want to weigh the outcome, I think you want Math.round(), Math.floor(), or Math.ceil().

It's been a long day, so if I'm way off here, somebody set me straight


--Rich

p.s. If you want to take a step closer to AS2, try strong datatyping your variables.

Devin
Posts: 15
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Post by Devin » Thu Aug 04, 2005 9:58 am

I see the problem now. panDiff/panWidth is definately not a String. Even if panDiff and panWidth are each strings and you try to divide them, you get NaN for the data type.

The question is which variables (if any) are strings? Once you know that you can use the parseInt function to convert each string to numbers individually. Here is something you can do to find this out. Comment out lines 67 and 72 then add this code right before Lines 67 and 72:

Code: Select all

trace("panDiff is a " + typeof(panDiff) + ", panWidth is a " + typeof(panWidth));
If both variables are strings then you could use parseInt on each one like this:

Code: Select all

soundVol = (parseInt(panDiff)/parseInt(panWidth))*100;
If only panDiff is a string then try this:

Code: Select all

soundVol = (parseInt(panDiff)/panWidth)*100;
Or if only panWidth is a string then try this:

Code: Select all

soundVol = (panDiff/parseInt(panWidth))*100;

mysg20
Posts: 4
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Post by mysg20 » Thu Aug 04, 2005 9:19 pm

Ok, I've tried both comments made using the Math.floor script and also the PanWidth. As a standalone player, it works fine, but when I publish it and try and us it in another document in a scrollpane component, it still doesn't work. Doesn't give me errors, but it just doesn't work. Any ideas?


Post Reply