Actionscript 3.0: объем

Код, который получает случайный результат:

int roll = dice.throwDice();

выполняется ровно один раз. Вы вызываете метод throw один раз . Вы сохраняете результат, а не «указатель» на функцию, которая будет вызываться повторно всякий раз, когда roll где-то используется.

Таким образом, вы должны поставить эту строку:

roll = dice.throwDice();
System.out.println("You have rolled " + roll + ".");

прямо перед тем местом, где вы ожидаете еще один бросок костей!

7
задан m.s. 19 October 2015 в 12:16
поделиться

2 ответа

You're a bit vague, but hopefully I'm getting you ;)

Scope for classes are generally pretty easy to handle, it mostly comes down to packages. Packages are created in a simple tree structure, and in ActionScript3 the filestructre has to follow the namespaces. Which makes it even easier.

You can access any class from anywhere, but if it's in another package you will need to "import" the class. This is done by writing an import statement in the beginning of class or interface where you need to use it. Like so:

import flash.display.MovieClip;

There is an exception to this rule, a class can be declared with the internal keyword, in which case the class will only be available within that package. This is mostly used for helper classes.

Basicly you should not worry about classes not being available.

NB: You create package with the package keyword.

1
ответ дан 7 December 2019 в 14:37
поделиться
Другие вопросы по тегам:

Похожие вопросы: