AS 1.0 Script, to AS 2.0 Scrirt

Do you use Script assist (aka V2 normal mode)? This is the forum for you.

AS 1.0 Script, to AS 2.0 Scrirt

Postby 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)
mysg20
 
Posts: 4
Joined: Mon Jun 30, 2003 5:56 pm


Re: AS 1.0 Script, to AS 2.0 Scrirt

Postby 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?
Devin
 
Posts: 15
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Postby 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.
mysg20
 
Posts: 4
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Postby 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.
var_rich:SqueekyWheel
 
Posts: 7
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Postby 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;
Devin
 
Posts: 15
Joined: Mon Jun 30, 2003 5:56 pm

Re: AS 1.0 Script, to AS 2.0 Scrirt

Postby 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?
mysg20
 
Posts: 4
Joined: Mon Jun 30, 2003 5:56 pm

juicycouture brand bags blog

Postby opqr543 » Wed Feb 24, 2010 8:08 pm

opqr543
 
Posts: 40
Joined: Sat Sep 19, 2009 9:29 am



Return to Script Assist in Flash 8

Who is online

Users browsing this forum: No registered users and 1 guest

cron