开发者

Tracing Variables in AS3 is not working

开发者 https://www.devze.com 2023-02-05 21:09 出处:网络
var a:Number; var b:Number; a + b = 17; trace (\"A: \"a\"B: \"b); 开发者_JS百科 Why does this not work? Is there somthing about tracing multiple pieces of information inthe same trace statement in
var a:Number;
var b:Number;

a + b = 17;

trace ("A: "a"       B: "b);
开发者_JS百科

Why does this not work? Is there somthing about tracing multiple pieces of information in the same trace statement in AS3?


You have two issues in your code. The one the other answers apply to is the trace problem. The argument of a trace() call is any number of strings, separated by comma's. However, it is very common to just supply one and concatenate the string parts with the + sign.

trace("A: "+a+", B: "+b);

The real problem in your code however is a + b = 17, both in writing and in thinking. You cannot calculate the numeric outcome of an equation if you have more than one undetermined variable in there. A + B = C is only solvable in code if you know two of the three variables. If you want to write something moderately useful, try

var a:Number = 5;
var b:Number;

b = 12 - a;

trace("A: "+a+", B: "+b);

Apart from the math thinking, in code you're not writing math equations, you're writing assignment expressions. Whatever expression is to the right of the = sign, will get assigned to the variable to the left of the = sign. It will never work to assign one expression to two variables with an operator (+, *, -, /, %, etc) and hope that the math will magically resolve itself. a + b = something will never work, something = a + b might. In addition, trying to assign something to a constant and hoping it will resolve itself, like 12 = a + b, will also not work.

Cheers.


You have to use the plus (+) symbol to concatenate strings together.

trace ("A: " + a + "B: " + b);


In ActionScript 3, the trace method can take many parameters. But they must be comma seperated like any method call. So you could use:

trace ("A:", a, "B:", b);
0

精彩评论

暂无评论...
验证码 换一张
取 消