tailieunhanh - O’Reilly Programming Flex 2 phần 7
Kết quả cuối cùng, file SWF, là hoàn toàn giống nhau, không nhanh hơn, không mạnh hơn, thậm chí kích cỡ sẽ bị phình ra khá nhiều nếu dùng Flex 4, so với Flex , bản hoàn thiện cuối cùng của thế hệ Flex 3. | Example 12-1. User class package public class User private var _nameFirst String private var _nameLast String private var _email String private var _lastLogin Date private var _userType uint public function get nameFirst String return _nameFirst public function set nameFirst value String void _nameFirst nameFirst public function get nameLast String return _nameLast public function set nameLast value String void _nameLast nameLast public function get email String return _email public function set email value String void var expression RegExp b - @ . A-Z 2 4 b i if value _email value else _email invalid email public function get lastLogin Date return _lastLogin public function set lastLogin value Date void _lastLogin lastLogin public function get userType uint return _userType 266 Chapter 12 Working with Data Example 12-1. User class continued public function set userType value uint void if userType 2 _userType userType public function User You can then create an instance of the model class using MXML or ActionScript. With MXML you have to define the namespace then use namespace Class to create the instance xml version encoding utf-8 mx Application xmlns mx http 2006 mxml xmlns data . . layout absolute data User id user email example@ lastLogin new Date nameFirst Abigail nameLast Smith userType 1 mx Application With ActionScript you need to import the class and then use the constructor as part of a new statement import private var user User private function initializeHandler event Event void user new User example@ etc. In the next section we ll look at data binding. If you want to enable the data binding feature for a custom ActionScript-based data model you must use the Bindable metatag when declaring the class Bindable public class User If you create the instance using MXML the .
đang nạp các trang xem trước