AS 1.0 Script, to AS 2.0 Scrirt
AS 1.0 Script, to AS 2.0 Scrirt
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"+ (100panVolume)
soundObj.setPan(panVolume)
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"+ (100panVolume)
soundObj.setPan(panVolume)
Re: AS 1.0 Script, to AS 2.0 Scrirt
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?
Re: AS 1.0 Script, to AS 2.0 Scrirt
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.
**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.

 Posts: 7
 Joined: Mon Jun 30, 2003 5:56 pm
Re: AS 1.0 Script, to AS 2.0 Scrirt
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.
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.
Re: AS 1.0 Script, to AS 2.0 Scrirt
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:
If both variables are strings then you could use parseInt on each one like this:
If only panDiff is a string then try this:
Or if only panWidth is a string then try this:
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));
Code: Select all
soundVol = (parseInt(panDiff)/parseInt(panWidth))*100;
Code: Select all
soundVol = (parseInt(panDiff)/panWidth)*100;
Code: Select all
soundVol = (panDiff/parseInt(panWidth))*100;
Re: AS 1.0 Script, to AS 2.0 Scrirt
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?