How to use Math.LN(x) in ActionScript 3 - actionscript-3

How to use Math.LN(x) in ActionScript 3?
I have a formula to convert:
17.867 * LN(x)-29.263
How to write in ActionScript 3? I'm confused about how to write it.
What I've tried :
var Kc:Number;
var value_x:Number;
function enterFrameHandler () : void
{
value_x=80;
Kc=(17.867)*Math.LN10(value_x) - 29.263;
value_Kc.text=String(Kc);
trace(Kc);
//y = 17.867ln(x) - 29.263//
}
enterFrameHandler();
Getting error :
Error : Scene 1, Layer 'Layer 1', Frame 1, Line 7, Column 19 1195 :
Attempted access of inaccessible method LN10 through a reference with
static type Class.

thanks for your replied #Organis may be directly show problem in my code
var Kc:Number;
var value_x:Number;
function enterFrameHandler () : void
{
value_x=80;
Kc=(17.867)*Math.LN10(value_x) - 29.263;
value_Kc.text=String(Kc);
trace(Kc);
//y = 17.867ln(x) - 29.263//
}
enterFrameHandler();
///get error Scene 1, Layer 'Layer 1', Frame 1, Line 7, Column 19 1195: Attempted access of inaccessible method LN10 through a reference with static type Class.//

Related

AS3 : 2 error 1061 and an error 1119

Sorry ahead of time for french in my code or badly translated errors (idk what they are in english so Google translate). I'm working on a program at school to add all numbers, all even numbers or all odd numbers (different buttons) from an array (seperate file, called U2A2_Elements.as) and I'm getting multiple errors, I'm getting :
1061: Call for indexOf method might not be defined via the static int type reference at entier = (entier.indexOf(entierSaisi));
1119: Access to the length property can not be defined via the reference type static int" at for (var i=entier; i entier.length; i++).
1061: Call for pop method might not be defined via the reference type static int" at entier.pop();.
Any help would be greatly appreciated as I have no idea what to do with the code nor does the teacher or anyone else.
EDIT: Forgot to put the link to the code http://pastebin.com/5nyf3z7g
In your supprimerFunction() function, you forgot that your array is mesEntiers ( and not entier which is an int object ), so I think that you should write :
function supprimerFunction(event:MouseEvent):void {
var entierSaisi:String;
var entier:int;
entierSaisi = (txtEntier.text);
entier = int(entierSaisi);
entier = mesEntiers.indexOf(entier);
if (entier != -1) {
for (var i = entier; i < mesEntiers.length; i++) {
entier[i] = entier[i + 1];
}
mesEntiers.pop();
}
}
Of course, I try just to remove errors mentioned in your question, and not improve your function.
Hope that can help.

Error #2109 half the time

I'm making a platform game in AS3.
Everything is running fine except sometimes (not each time I run the game), I've got this error :
ArgumentError: Error #2109: Frame label null not found in scene null.
at flash.display::MovieClip/gotoAndStop()
at PlatformGame/moveCharacter()[C:\...\PlatformGame.as:581]
at PlatformGame/moveEnemies()[C:\...\PlatformGame.as:360]
at PlatformGame/gameLoop()[C:\...\PlatformGame.as:348]
I don't understand AT ALL why it happens randomly..
Do you know what could be the problem ?
Here's the lines in the error :
line 581 :
char.mc.gotoAndStop(char.walkAnimation[Math.floor(char.animstep)]);
line 360 :
moveCharacter(enemies[i],timeDiff);
line 348 :
moveEnemies(timeDiff);
Thank you for your help,
You ask to 'mc' (contained in 'char') to go to the frame which number
is contained in the array 'walkAnimation' at the index: Math.floor(char.animstep).
The error you have got means that, for some reason, 'Math.floor(char.animstep)' index doesn't exist in the array 'walkAnimation'.
Exactly as if you wrote :
var frame:Array = [1, 2, 3];
gotoAndStop(frame[10]);
frame[0] is 1, frame[1] is 2, frame[2] is 3, but frame[10] is undefined.

AS3 syntax compile errors - expecting semicolon before rightparen

I know this is extremely basic but the following function is generating 2 syntax errors on compile, these are shown below. I can't figure them out. Any help is much appreciated.
Game, Layer 'Actions', Frame 2, Line 5 1086: Syntax error: expecting semicolon before rightparen.
Game, Layer 'Actions', Frame 2, Line 5 1084: Syntax error: expecting rightbrace before semicolon.
function fl_TouchEndHandler_2(event:TouchEvent):void {
// Drag & drop stuff...
contained[i] = Gem1_MC.hitTestObject(Gem4_MC));
contained[i] = Gem2_MC.hitTestObject(Gem4_MC));
contained[i] = Gem3_MC.hitTestObject(Gem4_MC));
if (contained.indexOf(false) == -1) { // This returns -1 if it can't find false
gotoAndStop(1);
}
}
You have extra ')'
try:
function fl_TouchEndHandler_2(event:TouchEvent):void {
// Drag & drop stuff...
contained[i] = Gem1_MC.hitTestObject(Gem4_MC);
contained[i] = Gem2_MC.hitTestObject(Gem4_MC);
contained[i] = Gem3_MC.hitTestObject(Gem4_MC);
if (contained.indexOf(false) == -1) { // This returns -1 if it can't find false
gotoAndStop(1);
}
}

ArgumentError: Error #1063 issue

This is usually a simple error, yet I cannot find an obvious answer.
The full error is: 'ArgumentError: Error #1063: Argument count mismatch on com::previewSelection/selectionOn(). Expected 2, got 1.'
The obvious issue is that I'm only giving 1 bit of information and not 2, however I am definitely giving 2.
Main code:
function previewOn(e){
previewTile2.selectionOn(holdBar_mc, area1_mc);
previewTile2.removeEventListener(MouseEvent.CLICK, previewOn);
previewTile2.addEventListener(MouseEvent.CLICK, previewOff);
stage.setChildIndex(previews, 1);
var editOpen:Tween = new Tween(editTab, 'x', Strong.easeOut, editTab.x, -215, 1, true);
createTiles();
}
And the class file function:
public function selectionOn(holdBar:MovieClip, area1:MovieClip){
holdBarDown = new Tween(holdBar, 'y', Strong.easeOut, holdBar.y, 518, 1, true);
area1Up = new Tween(area1, 'y', Strong.easeOut, area1.y, area1.y - 300, 1, true);
}
Neither holdBar_mc or area1_mc are 'null' when traced.
The file runs without issue or slow-down, yet the Argument error constantly returns. Any ideas?

AS3 sortOn woes

I have an Array called alarmQueue. I'm pushing a new arrays in to it with the contents [hours:int, minutes:int, seconds:int] and I'd like to use alarmQueue.sortOn() to sort the queue of alarms Ascending but I'm having problems getting my head around the logic.
// the function to push the alarm in to a queue
public function setAlarm(_hours:int = 0, _minutes:int = 0, _seconds:int = 0):void
{
var alarmAsArray:Array = new Array(_hours, _minutes, _seconds);
alarmQueue.push(alarmAsArray);
alarmQueue.sortOn([0, [1, 2]], Array.NUMERIC | Array.DESCENDING);
trace(alarmQueue);
}
I'm setting these alarms:
clock.setAlarm(1, 0, 31); // alarm 1
clock.setAlarm(12, 1, 21); // alarm 2
clock.setAlarm(12, 1, 19); // alarm 3
and getting the following traces:
1,0,31
12,1,21,1,0,31
12,1,21,12,1,19,1,0,31
I seem to be ordering them as: alarm 2, alarm 3, alarm 1
but I want to be ordering them by hour, then minute and seconds.
Can anyone shed any light on my sorting woes?
Cheers!
thanks for the feedback.
I've tested:
alarmQueue.push(
{
hours: _hours,
minutes: _minutes,
seconds: _seconds
});
alarmQueue.sortOn(
['hours', 'minutes', 'seconds'],
[Array.NUMERIC | Array.ASCENDING, Array.NUMERIC | Array.ASCENDING, Array.NUMERIC | Array.ASCENDING]
);
if(alarmQueue.length == 3)
{
for(var i:int = 0; i SMALLERTHAN alarmQueue.length; i++)
{
trace(alarmQueue[i].hours,alarmQueue[i].minutes, alarmQueue[i].seconds);
}
}
I had to change the trace slightly due to the array items being objects now and used SMALLERTHAN as the < symbol seems to break to code tags here, but the app wouldn't compile as Flex Builder was telling me Array.ASCENDING not being a sort method, so I checked livedocs and found no mention of it there too. Any other guesses?
This should work, but I have not tested it.
public function setAlarm(_hours:int = 0, _minutes:int = 0, _seconds:int = 0):void
{
alarmQueue.push(
{
hours: _hours,
minutes: _minutes,
seconds: _seconds
});
alarmQueue.sortOn(['hours', 'minutes', 'seconds'], Array.NUMERIC);
}
Found the answer after some tinkering. The default method of sorting is ascending but there's no option to set Ascending as a secondry sorting method. So by performing two sorts, the first descending on the minutes and seconds, the second is a sortOn the hours with no parameter applied so it sorts ascending!
var alarmAsArray:Array = new Array(_hours, _minutes, _seconds);
alarmQueue.push(alarmAsArray);
alarmQueue.sortOn([1, 2]);
alarmQueue.sortOn([0], Array.DESCENDING);
if(alarmQueue.length == 3)
{
trace(alarmQueue);
}
this gives the correct output of: 12,1,19 12,1,21 1,0,31
Many thanks all!
ant