![]() |
|
||||||||||
|
|||||
попытался я разбить один кусок кода на 2 и у меня нечего не вышло..вот код целого куска: package CaptureUserInput { import flash.events.*; import flash.text.*; import flash.display.Stage; import flash.display.*; public class CaptureUserInput extends Sprite { private var myTextBox:TextField = new TextField(); private var myOutputBox:TextField = new TextField(); private var myText:String = "Type your text "; public function CaptureUserInput() { captureText(); greetingapp(); } public function captureText():void { myTextBox.type = TextFieldType.INPUT; myTextBox.x = 10; myTextBox.y = 10; myTextBox.backgroundColor=0xFF0000; myTextBox.background = true; addChild(myTextBox); myTextBox.text = myText; myTextBox.addEventListener(TextEvent.TEXT_INPUT, textInputCapture); } public function textInputCapture(event:TextEvent):void { var str:String = myTextBox.text; createOutputBox(str); } public function createOutputBox(str:String):void { myOutputBox.background = true; myOutputBox.backgroundColor=0x00FF00; myOutputBox.x = 200; myOutputBox.y = 10; addChild(myOutputBox); myOutputBox.text = str; } public function greetingapp () { var circle:Sprite = new Sprite(); circle.graphics.lineStyle (1); circle.graphics.beginFill (0xFF00CC, 1); circle.graphics.drawCircle (50, 100, 50); circle.x = 275; circle.y = 235; circle.addEventListener (MouseEvent.CLICK, onMouseClick); addChild(circle); } private function onMouseClick (event:MouseEvent):void { trace("sss"); } } } ![]() что мне нужно добавить в основной код, что бы он запускал код из соседнего файла? |
|
|||||
|
Регистрация: Jul 2009
Адрес: Москва
Сообщений: 99
|
Создайте в соседнем файле новый класс и сделайте функцию greetingapp() его публичным методом
|
|
|||||
|
[+6 23.11.09]
|
а зачем это надо? пусть в одном куске будет!
|
|
|||||
|
да я вроде так и сделал..
основной кусок: package CaptureUserInput { import flash.events.*; import flash.text.*; import flash.display.Stage; import flash.display.*; public class CaptureUserInput extends Sprite { private var myTextBox:TextField = new TextField(); private var myOutputBox:TextField = new TextField(); private var myText:String = "Type your text "; public function CaptureUserInput() { captureText(); } public function captureText():void { myTextBox.type = TextFieldType.INPUT; myTextBox.x = 10; myTextBox.y = 10; myTextBox.backgroundColor=0xFF0000; myTextBox.background = true; addChild(myTextBox); myTextBox.text = myText; myTextBox.addEventListener(TextEvent.TEXT_INPUT, textInputCapture); } public function textInputCapture(event:TextEvent):void { var str:String = myTextBox.text; createOutputBox(str); } public function createOutputBox(str:String):void { myOutputBox.background = true; myOutputBox.backgroundColor=0x00FF00; myOutputBox.x = 200; myOutputBox.y = 10; addChild(myOutputBox); myOutputBox.text = str; } } } package CaptureUserInput { import flash.display.Stage; import flash.display.*; import flash.events.*; public class greetingapp extends Sprite { public function greetingapp() { greetingapp(); } public function greetingapp () { var circle:Sprite = new Sprite(); circle.graphics.lineStyle (1); circle.graphics.beginFill (0xFF00CC, 1); circle.graphics.drawCircle (50, 100, 50); circle.x = 275; circle.y = 235; circle.addEventListener (MouseEvent.CLICK, onMouseClick); addChild(circle); } private function onMouseClick (event:MouseEvent):void { trace("sss"); } } } |
|
|||||
|
создаёшь новый класс с именем ShapeCreator, пишешь:
package { import flash.display.Sprite; public class ShapeCreator { static function createCircle (x:int, y:int, r:int, color:Number, alpha:Number = 1):Sprite { var circle:Sprite = new Sprite(); circle.graphics.lineStyle(1); circle.graphics.beginFill(color, alpha); circle.graphics.drawCircle(x, y, r); return circle; } } } Можно конечно всё сделать в одном методе, но это сильно усложняет чтение кода. |
|
|||||
|
Регистрация: Sep 2008
Адрес: Москва
Сообщений: 224
|
Достаточно медленное существо, у тому же меняющее порядок отображения - аккуратней с ним.
И как alecsisk написал, лучше не делать, делайте по человечески. public class Circle extends Sprite { private var _color:uint; private var _alpha:Number; private var _rad:Number; public function Circle(radius:Number = 10, color:uint = 0x000000, alpha:Number = 1) { _rad = radius; _color = color; _alpha = alpha; draw(); } private function draw():void { var gr:Graphics = graphics; gr.beginFill(_color,_alpha); gr.drawCircle(0,0,_rad); gr.endFill(); } public function set radius(value:Number):void { if (_rad != value) { _rad = value; draw(); } } public function get radius():Number { return _rad; } // и т.д } ![]() |
|
|||||
|
возможно вам нужно получше разобраться в то что вы делаете. Так как задача тривиальная.
|
|
|||||
|
|
|
|||||
|
Регистрация: Sep 2008
Адрес: Москва
Сообщений: 224
|
alecsisk, можно вопрос, зачем вы разделяете код? Случаем не для того, чтоб у пользователей мобильный устройств, при просмотре кода не было полосы прокрутки?
![]() package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFieldType; import flash.text.TextFieldAutoSize; import flash.events.TextEvent; public class Main extends Sprite { private var _tf1:TextField = new TextField(); private var _tf2:TextField = new TextField(); private var _gap:Number = 10; public function Main () { var circle:Circle = new Circle(); circle.x = 275; circle.y = 235; circle.radius = 100; circle.color = 0xFF0000; circle.alpha = 0.4; addChild(circle); circle.addEventListener (MouseEvent.CLICK, onMouseClick); _tf1.type = TextFieldType.INPUT; addChild(_tf1); _tf1.background = true; _tf1.backgroundColor = 0xFF00FF; _tf1.multiline = true; _tf1.wordWrap = true; _tf2.autoSize = TextFieldAutoSize.LEFT; addChild(_tf2); _tf2.background = false; _tf2.wordWrap = true; _tf2.width = _tf1.width; _tf2.x = _tf1.width + _gap; _tf1.addEventListener(TextEvent.TEXT_INPUT,onTextInput); } private function onTextInput(e:TextEvent):void { _tf2.text = _tf1.text + e.text; } private function onMouseClick (e:Event):void { trace("click"); } } } package { import flash.display.Sprite; import flash.display.Graphics; public class Circle extends Sprite { private var _color:uint; private var _alpha:Number; private var _rad:Number; public function Circle(radius:Number = 10, color:uint = 0x000000, alpha:Number = 1) { _rad = radius; _color = color; _alpha = alpha; draw(); } private function draw():void { var gr:Graphics = graphics; gr.clear(); gr.beginFill(_color,_alpha); gr.drawCircle(0,0,_rad); gr.endFill(); } public function set radius(value:Number):void { if (_rad != value) { _rad = value; draw(); } } public function get radius():Number { return _rad; } public function set color(value:Number):void { if (_color != value) { _color = value; draw(); } } public function get color():Number { return _color; } override public function set alpha(value:Number):void { if (_alpha != value) { _alpha = value; draw(); } } override public function get alpha():Number { return _alpha; } final public function set $alpha(value:Number):void { super.alpha = value; } final public function get $alpha():Number { return super.alpha; } // и т.д } } |
![]() |
![]() |
Часовой пояс GMT +4, время: 02:21. |
|
|
« Предыдущая тема | Следующая тема » |
|
|