Вверх

Блог
RSS лента

Ответить на комментарий

Позиционирование объектов на сцене

Допустим, у нас есть некие обьекты на сцене, и мы хотим их разместить по краям и в центре. При изменении размеров сцены они должны оставаться на своих местах в процентном соотношении к размерам сцены. Я покажу пример на текстовых полях, а использовать можно и с мувиками, и с чем угодно. Итак, создаём новый документ и в первом кадре рута пишем:

  1. array = ["TL", "TC", "TR", "CL", "CC", "CR", "BL", "BC", "BR"];
  2. var len = array.length;
  3. for (var i = 0; i<len; i++) {
  4. _root.createTextField("tf"+i, i, 0, 0, 100, 20);
  5. var tf = _root["tf"+i];
  6. tf.border = true;
  7. tf.text = array[i];
  8. }
  9. //
  10. Stage.scaleMode = "noScale";
  11. Stage.align = "TL";
  12. onResize = function () {
  13. tf0._x = 0;
  14. tf0._y = 0;
  15. //
  16. tf1._x = (Stage.width-tf1._width)/2;
  17. tf1._y = 0;
  18. //
  19. tf2._x = Stage.width-tf2._width;
  20. tf2._y = 0;
  21. //
  22. tf3._x = 0;
  23. tf3._y = (Stage.height-tf3._height)/2;
  24. //
  25. tf4._x = (Stage.width-tf4._width)/2;
  26. tf4._y = (Stage.height-tf4._height)/2;
  27. //
  28. tf5._x = Stage.width-tf5._width;
  29. tf5._y = (Stage.height-tf5._height)/2;
  30. //
  31. tf6._x = 0;
  32. tf6._y = Stage.height-tf6._height;
  33. //
  34. tf7._x = (Stage.width-tf7._width)/2;
  35. tf7._y = Stage.height-tf7._height;
  36. //
  37. tf8._x = Stage.width-tf8._width;
  38. tf8._y = Stage.height-tf8._height;
  39. };
  40. Stage.addListener(this);

Ещё раз обращу внимание на то, что мы можем легко вытаскивать мувики на сцену и управлять ими, указав нужные координаты в функции onResize.

Ваша оценка: Пусто Средняя: 3 (2 голосов)

Ответить

 
  • Адреса страниц и электронной почты автоматически преобразуются в ссылки.
  • Строки и параграфы переносятся автоматически.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Image links from G2 are formatted for use with Lightbox2
  • Image links with 'rel="lightshow"' in the <a> tag will appear in a Lightbox slideshow when clicked on.
  • Links to HTML content with 'rel="lightframe"' in the <a> tag will appear in a Lightbox when clicked on.
  • Links to video content with 'rel="lightvideo"' in the <a> tag will appear in a Lightbox when clicked on.
  • Links to inline or modal content with 'rel="lightmodal"' in the <a> tag will appear in a Lightbox when clicked on.

Подробнее о форматировании

Главная | Портфолио | Услуги | Контакты | Блог