- AS3 getting a textField.text on Click Event
- //on the cycle
- MiniInfo.addEventListener(MouseEvent.CLICK, OpenWorkDetails);
- //further down the code
- public function OpenWorkDetails(e:MouseEvent):void
- {
- trace(MiniInfo.IDTrabalhoField.text);
- //If I figure this number out, I will change it to addChild
- }
- package
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.net.URLLoader;
- import flash.net.URLRequest;
- import flash.net.URLRequestMethod;
- import flash.net.URLVariables;
- [SWF(width="275", height="175")]
- public class Main extends Sprite
- {
- private var _phpPath:String = "http://localhost/stackoverflow/minibiginfos/getBigInfo.php";
- private var _bigInfo:BigInfo;
- public function Main():void
- {
- if (stage) init();
- else addEventListener(Event.ADDED_TO_STAGE, init);
- }// end function
- private function init(e:Event = null):void
- {
- removeEventListener(Event.ADDED_TO_STAGE, init);
- var xml:XML = <miniInfos>
- <miniInfo id="1" text="Mini Info 1" />
- <miniInfo id="2" text="Mini Info 2" />
- <miniInfo id="3" text="Mini Info 3" />
- </miniInfos>;
- for (var i:uint = 0; i < xml.children().length(); i++)
- {
- var miniInfo:MiniInfo = new MiniInfo(xml.miniInfo[i].@id,
- xml.miniInfo[i].@text);
- miniInfo.x = 25;
- miniInfo.y = 25 + ((miniInfo.height + 25) * i);
- addChild(miniInfo);
- miniInfo.addEventListener(MouseEvent.CLICK, onMiniInfoClick);
- }// end for
- }// end function
- private function onMiniInfoClick(e:MouseEvent):void
- {
- loadBigInfo(MiniInfo(e.currentTarget).id);
- }// end function
- private function loadBigInfo(id:int):void
- {
- if (!_bigInfo)
- {
- _bigInfo = new BigInfo();
- _bigInfo.x = 150;
- _bigInfo.y = 25;
- addChild(_bigInfo);
- }// end if
- var urlVariables:URLVariables = new URLVariables();
- urlVariables.miniInfoID = id;
- var urlRequest:URLRequest = new URLRequest(_phpPath);
- urlRequest.method = URLRequestMethod.POST;
- urlRequest.data = urlVariables;
- var urlLoader:URLLoader = new URLLoader(urlRequest);
- urlLoader.addEventListener(Event.COMPLETE, onURLLoaderComplete);
- urlLoader.load(urlRequest);
- }// end function
- private function onURLLoaderComplete(e:Event):void
- {
- var urlLoader:URLLoader = URLLoader(e.currentTarget);
- var urlVariables:URLVariables = new URLVariables(urlLoader.data);
- _bigInfo.text = urlVariables.text;
- }// end function
- }// end class
- }// end package
- import flash.display.Sprite;
- import flash.text.TextField;
- internal class MiniInfo extends Sprite
- {
- private var _id:int;
- private var _text:String
- private var _width:Number = 100;
- private var _height:Number = 25;
- override public function get width():Number { return _width }
- override public function get height():Number { return _height }
- public function get id():int { return _id }
- public function get text():String { return _text }
- public function MiniInfo(id:int, text:String):void
- {
- _id = id;
- _text = text;
- graphics.beginFill(0xE1E1E1);
- graphics.drawRect(0, 0, _width, _height);
- graphics.endFill();
- var textField:TextField = new TextField();
- textField.x = textField.y = 5;
- textField.text = text;
- textField.mouseEnabled = false;
- addChild(textField);
- }// end function
- }// end class
- internal class BigInfo extends Sprite
- {
- private var _width:Number = 100;
- private var _height:Number = 125;
- private var _textField:TextField;
- public function get text():String { return _textField.text }
- public function set text(text:String):void { _textField.text = text; }
- public function BigInfo()
- {
- graphics.beginFill(0xE1E1E1);
- graphics.drawRect(0, 0, _width, _height);
- graphics.endFill();
- _textField = new TextField();
- _textField.width = 90;
- _textField.wordWrap = true;
- _textField.x = _textField.y = 5;
- _textField.mouseEnabled = false;
- addChild(_textField);
- }// end function
- }// end class
- <?php
- if(!empty($_POST))
- {
- $bigInfos = array
- (
- array
- (
- 'miniInfoID' => 1,
- 'text' => "This is the big info for mini info 1"
- ),
- array
- (
- 'miniInfoID' => 2,
- 'text' => "This is the big info for mini info 2"
- ),
- array
- (
- 'miniInfoID' => 3,
- 'text' => "This is the big info for mini info 3"
- )
- );
- $text;
- for($i = 0; $i < sizeof($bigInfos); $i++)
- {
- foreach($bigInfos as $item)
- {
- if($item['miniInfoID'] == (int)$_POST['miniInfoID'])
- {
- $text = $item['text'];
- break;
- }
- }// end foreach
- break;
- }// end for
- print "text=$text";
- }// end if
- ?>
- public function OpenWorkDetails(e:MouseEvent):void{
- trace((e.currentTarget as MiniInfo).IDTrabalhoField.text);
- }