reworking custom version of 03d3 to better understand separation of concerns, whatever ...
This commit is contained in:
parent
ce8ff91b3f
commit
4ebee454f9
@ -1,12 +1,16 @@
|
|||||||
package
|
package
|
||||||
{
|
{
|
||||||
import mx.core.Application;
|
import flash.events.MouseEvent;
|
||||||
|
|
||||||
import mx.collections.ArrayCollection;
|
import mx.collections.ArrayCollection;
|
||||||
import mx.rpc.events.ResultEvent;
|
import mx.controls.Alert;
|
||||||
import mx.events.ListEvent;
|
import mx.controls.Button;
|
||||||
import mx.rpc.http.HTTPService;
|
import mx.controls.List;
|
||||||
import mx.controls.Text;
|
import mx.controls.Text;
|
||||||
|
import mx.core.Application;
|
||||||
|
import mx.events.ListEvent;
|
||||||
|
import mx.rpc.events.FaultEvent;
|
||||||
|
import mx.rpc.events.ResultEvent;
|
||||||
|
import mx.rpc.http.HTTPService;
|
||||||
|
|
||||||
public class ListApp extends Application
|
public class ListApp extends Application
|
||||||
{
|
{
|
||||||
@ -14,19 +18,65 @@ package
|
|||||||
public var employeeList:ArrayCollection = new ArrayCollection();
|
public var employeeList:ArrayCollection = new ArrayCollection();
|
||||||
public var employeesService:HTTPService;
|
public var employeesService:HTTPService;
|
||||||
public var textMessage:Text;
|
public var textMessage:Text;
|
||||||
|
public var mylist:List;
|
||||||
|
public var mybutton:Button;
|
||||||
|
|
||||||
function ListApp()
|
public static const employeesServiceUrl:String =
|
||||||
|
"http://localhost:18080/employees.xml";
|
||||||
|
|
||||||
|
public function appComplete():void
|
||||||
{
|
{
|
||||||
|
_initButtonControl();
|
||||||
|
_initListControl();
|
||||||
|
_initEmployeesService();
|
||||||
|
trace(this + " initialized!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requestEmployees():void
|
private function _initButtonControl():void
|
||||||
{
|
{
|
||||||
|
trace(this + "._initButtonControl()");
|
||||||
|
mybutton.addEventListener(MouseEvent.CLICK, requestEmployees);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _initListControl():void
|
||||||
|
{
|
||||||
|
trace(this + "._initListControl()");
|
||||||
|
mylist.addEventListener(ListEvent.ITEM_CLICK, showMessage);
|
||||||
|
trace(this + ".mylist.dataProvider = " + mylist.dataProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _initEmployeesService():void
|
||||||
|
{
|
||||||
|
trace(this + "._initEmployeesService()");
|
||||||
|
employeesService = new HTTPService();
|
||||||
|
employeesService.url = employeesServiceUrl;
|
||||||
|
employeesService.method = "GET";
|
||||||
|
employeesService.resultFormat = "object";
|
||||||
|
employeesService.addEventListener("result", resultHandler);
|
||||||
|
employeesService.addEventListener("fault", faultHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requestEmployees(event:Event):void
|
||||||
|
{
|
||||||
|
trace(this + ".requestEmployees(" + event + ")");
|
||||||
employeesService.send();
|
employeesService.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resultHandler(event:ResultEvent):void
|
public function resultHandler(event:ResultEvent):void
|
||||||
{
|
{
|
||||||
|
trace(this + ".resultHandler(" + event + ")");
|
||||||
|
trace(this + " event.result = " + event.result);
|
||||||
|
trace(this + " event.headers = " + event.headers);
|
||||||
|
trace(this + " event.statusCode = " + event.statusCode);
|
||||||
|
trace(this + " event.result.employees = " + event.result.employees);
|
||||||
employeeList = event.result.employees.employee as ArrayCollection;
|
employeeList = event.result.employees.employee as ArrayCollection;
|
||||||
|
// mylist.dataProvider = employeeList;
|
||||||
|
trace(this + ".employeeList = " + employeeList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function faultHandler(event:FaultEvent):void {
|
||||||
|
var faultstring:String = event.fault.faultString;
|
||||||
|
Alert.show(faultstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showMessage(event:Event):void
|
public function showMessage(event:Event):void
|
||||||
|
@ -1,26 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<loc:ListApp xmlns:mx="http://www.adobe.com/2006/mxml"
|
<loc:ListApp xmlns:loc="*"
|
||||||
xmlns:loc="*"
|
xmlns:mx="http://www.adobe.com/2006/mxml"
|
||||||
backgroundColor="#FFFFFF"
|
applicationComplete="appComplete();">
|
||||||
backgroundAlpha="0"
|
<mx:Style source="listapp.css" />
|
||||||
horizontalAlign="left"
|
<mx:Button id="mybutton" label="Return Employees" />
|
||||||
verticalGap="15" horizontalGap="15">
|
<mx:List id="mylist" styleName="basic-list"
|
||||||
|
dataProvider="{employeeList}" labelField="firstName" />
|
||||||
<mx:HTTPService
|
<mx:Text id="textMessage" styleName="basic-text" />
|
||||||
id="employeesService"
|
|
||||||
url="http://www.flexmonkeys.com/F3GSE/PartIII/CRUD/employees.xml"
|
|
||||||
result="resultHandler(event)"/>
|
|
||||||
|
|
||||||
<mx:Button label="Return Employees"
|
|
||||||
click="requestEmployees()" />
|
|
||||||
|
|
||||||
<mx:List id="mylist"
|
|
||||||
labelField="firstName"
|
|
||||||
dataProvider="{employeeList}"
|
|
||||||
width="200" height="200"
|
|
||||||
itemClick="showMessage(event)"/>
|
|
||||||
|
|
||||||
<mx:Text id="textMessage"
|
|
||||||
paddingTop="20" />
|
|
||||||
|
|
||||||
</loc:ListApp>
|
</loc:ListApp>
|
||||||
|
66
custom-03d3-lists/employees.py
Normal file
66
custom-03d3-lists/employees.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import sys
|
||||||
|
from wsgiref.simple_server import make_server
|
||||||
|
|
||||||
|
|
||||||
|
EMPLOYEES_XML = """\
|
||||||
|
<employees>
|
||||||
|
<employee id="101" code="233">
|
||||||
|
<firstName>Bob</firstName>
|
||||||
|
<lastName>Costas</lastName>
|
||||||
|
</employee>
|
||||||
|
<employee id="102" code="233">
|
||||||
|
<firstName>Bob</firstName>
|
||||||
|
<lastName>Sagat</lastName>
|
||||||
|
</employee>
|
||||||
|
<employee id="103" code="233">
|
||||||
|
<firstName>Harbor</firstName>
|
||||||
|
<lastName>Oaks</lastName>
|
||||||
|
</employee>
|
||||||
|
<employee id="104" code="233">
|
||||||
|
<firstName>Oak</firstName>
|
||||||
|
<lastName>Barrel</lastName>
|
||||||
|
</employee>
|
||||||
|
<employee id="105" code="233">
|
||||||
|
<firstName>Sag</firstName>
|
||||||
|
<lastName>Harbor</lastName>
|
||||||
|
</employee>
|
||||||
|
</employees>
|
||||||
|
"""
|
||||||
|
EMPLOYEES_XML_LEN = str(len(EMPLOYEES_XML))
|
||||||
|
CROSSDOMAIN_XML = """\
|
||||||
|
<cross-domain-policy>
|
||||||
|
<allow-access-from domain="*"/>
|
||||||
|
</cross-domain-policy>
|
||||||
|
"""
|
||||||
|
CROSSDOMAIN_XML_LEN = str(len(CROSSDOMAIN_XML))
|
||||||
|
|
||||||
|
|
||||||
|
def main(sysargs=sys.argv[:]):
|
||||||
|
server = make_server('0.0.0.0', 18080, employees_app)
|
||||||
|
server.serve_forever()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def employees_app(environ, start_response):
|
||||||
|
path_info = environ.get('PATH_INFO', '/').strip(' /')
|
||||||
|
if path_info == 'employees.xml':
|
||||||
|
start_response('200 OK', [
|
||||||
|
('content-type', 'text/xml'),
|
||||||
|
('content-length', EMPLOYEES_XML_LEN),
|
||||||
|
])
|
||||||
|
return [EMPLOYEES_XML]
|
||||||
|
elif path_info == 'crossdomain.xml':
|
||||||
|
start_response('200 OK', [
|
||||||
|
('content-type', 'text/xml'),
|
||||||
|
('content-length', CROSSDOMAIN_XML_LEN),
|
||||||
|
])
|
||||||
|
return [CROSSDOMAIN_XML]
|
||||||
|
else:
|
||||||
|
start_response('404 Not Found', [('content-type', 'text/plain')])
|
||||||
|
return ['sorry charlie']
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
||||||
|
|
||||||
|
# vim:filetype=python
|
16
custom-03d3-lists/listapp.css
Normal file
16
custom-03d3-lists/listapp.css
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
ListApp {
|
||||||
|
backgroundColor: #ffffff;
|
||||||
|
backgroundAlpha: 0;
|
||||||
|
horizontalAlign: left;
|
||||||
|
verticalGap: 15;
|
||||||
|
horizontalGap: 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
.basic-list {
|
||||||
|
width: 200;
|
||||||
|
height: 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.basic-text {
|
||||||
|
paddingTop: 20;
|
||||||
|
}
|
14
mktargets.py
14
mktargets.py
@ -29,6 +29,7 @@ class TargetMaker(object):
|
|||||||
pathjoin(HERE, '[0-9]*-*', '*.mxml'),
|
pathjoin(HERE, '[0-9]*-*', '*.mxml'),
|
||||||
pathjoin(HERE, 'custom-*', '*.mxml'),
|
pathjoin(HERE, 'custom-*', '*.mxml'),
|
||||||
)
|
)
|
||||||
|
_sibling_fileexts = ('.as', '.css')
|
||||||
|
|
||||||
def __init__(self, outstream=sys.stdout):
|
def __init__(self, outstream=sys.stdout):
|
||||||
self.outstream = outstream
|
self.outstream = outstream
|
||||||
@ -45,10 +46,15 @@ class TargetMaker(object):
|
|||||||
as_swf = re.sub('(.*)\.mxml$', '\\1.swf', rel_mxml)
|
as_swf = re.sub('(.*)\.mxml$', '\\1.swf', rel_mxml)
|
||||||
self.targets[as_swf] = set([rel_mxml])
|
self.targets[as_swf] = set([rel_mxml])
|
||||||
|
|
||||||
as3_pattern = re.sub('(.*)/(.*)\.mxml$', '\\1/*.as', rel_mxml)
|
self._add_deps_from_sibling_file_extensions(as_swf, rel_mxml)
|
||||||
for local_as3 in glob.glob(as3_pattern):
|
|
||||||
rel_as3 = os.path.relpath(local_as3, HERE)
|
def _add_deps_from_sibling_file_extensions(self, as_swf, rel_mxml):
|
||||||
self.targets[as_swf].add(rel_as3)
|
for fileext in self._sibling_fileexts:
|
||||||
|
sibling_glob = re.sub('(.*)/(.*)\.mxml$', '\\1/*' + fileext,
|
||||||
|
rel_mxml)
|
||||||
|
for sibling in glob.glob(sibling_glob):
|
||||||
|
rel_sibling = os.path.relpath(sibling, HERE)
|
||||||
|
self.targets[as_swf].add(rel_sibling)
|
||||||
|
|
||||||
def _write_out_targets(self):
|
def _write_out_targets(self):
|
||||||
print(AUTOGEN_WARNING, file=self.outstream)
|
print(AUTOGEN_WARNING, file=self.outstream)
|
||||||
|
@ -143,7 +143,7 @@ custom-03d2-item-renderers/WeatherDisplay.swf: custom-03d2-item-renderers/Weathe
|
|||||||
$(MXMLC) custom-03d2-item-renderers/WeatherDisplay.mxml -warnings -l+=custom-03d2-item-renderers -output custom-03d2-item-renderers/WeatherDisplay.swf
|
$(MXMLC) custom-03d2-item-renderers/WeatherDisplay.mxml -warnings -l+=custom-03d2-item-renderers -output custom-03d2-item-renderers/WeatherDisplay.swf
|
||||||
|
|
||||||
|
|
||||||
custom-03d3-lists/ListControl.swf: custom-03d3-lists/ListControl.mxml custom-03d3-lists/ListApp.as
|
custom-03d3-lists/ListControl.swf: custom-03d3-lists/ListControl.mxml custom-03d3-lists/listapp.css custom-03d3-lists/ListApp.as
|
||||||
$(MXMLC) custom-03d3-lists/ListControl.mxml -warnings -l+=custom-03d3-lists -output custom-03d3-lists/ListControl.swf
|
$(MXMLC) custom-03d3-lists/ListControl.mxml -warnings -l+=custom-03d3-lists -output custom-03d3-lists/ListControl.swf
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user