Spark-shell启动的时候报Error while instantiating ‘org.apache.spark.sql.hive.HiveSessionStateBuilder’错误

版权声明:未经允许,随意转载,请附上本文链接谢谢(づ ̄3 ̄)づ╭❤~
https://blog.csdn.net/xiaoduan_/article/details/79815692

Spark-shell启动的时候报java.lang.IllegalArgumentException: Error while instantiating ‘org.apache.spark.sql.hive.HiveSessionStateBuilder’和error: not found: value spark,error: not found: value spark错误

具体报错信息如下

o adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
18/04/04 12:14:18 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
18/04/04 12:14:23 WARN conf.HiveConf: HiveConf of name hive.metastore.scheame.verification does not exist
18/04/04 12:14:26 WARN conf.HiveConf: HiveConf of name hive.metastore.scheame.verification does not exist
java.lang.IllegalArgumentException: Error while instantiating 'org.apache.spark.sql.hive.HiveSessionStateBuilder':
  at org.apache.spark.sql.SparkSession$.org$apache$spark$sql$SparkSession$$instantiateSessionState(SparkSession.scala:1053)
  at org.apache.spark.sql.SparkSession$$anonfun$sessionState$2.apply(SparkSession.scala:130)
  at org.apache.spark.sql.SparkSession$$anonfun$sessionState$2.apply(SparkSession.scala:130)
  at scala.Option.getOrElse(Option.scala:121)
  at org.apache.spark.sql.SparkSession.sessionState$lzycompute(SparkSession.scala:129)
  at org.apache.spark.sql.SparkSession.sessionState(SparkSession.scala:126)
  at org.apache.spark.sql.SparkSession$Builder$$anonfun$getOrCreate$5.apply(SparkSession.scala:938)
  at org.apache.spark.sql.SparkSession$Builder$$anonfun$getOrCreate$5.apply(SparkSession.scala:938)
  at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:99)
  at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:99)
  at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:230)
  at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:40)
  at scala.collection.mutable.HashMap.foreach(HashMap.scala:99)
  at org.apache.spark.sql.SparkSession$Builder.getOrCreate(SparkSession.scala:938)
  at org.apache.spark.repl.Main$.createSparkSession(Main.scala:97)
  ... 47 elided
Caused by: org.apache.spark.sql.AnalysisException: java.lang.RuntimeException: java.net.ConnectException: Call From anthony-air.local/169.254.89.73 to localhost:8020 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused;
  at org.apache.spark.sql.hive.HiveExternalCatalog.withClient(HiveExternalCatalog.scala:106)
  at org.apache.spark.sql.hive.HiveExternalCatalog.databaseExists(HiveExternalCatalog.scala:193)
  at org.apache.spark.sql.internal.SharedState.externalCatalog$lzycompute(SharedState.scala:105)
  at org.apache.spark.sql.internal.SharedState.externalCatalog(SharedState.scala:93)
  at org.apache.spark.sql.hive.HiveSessionStateBuilder.externalCatalog(HiveSessionStateBuilder.scala:39)
  at org.apache.spark.sql.hive.HiveSessionStateBuilder.catalog$lzycompute(HiveSessionStateBuilder.scala:54)
  at org.apache.spark.sql.hive.HiveSessionStateBuilder.catalog(HiveSessionStateBuilder.scala:52)
  at org.apache.spark.sql.hive.HiveSessionStateBuilder.catalog(HiveSessionStateBuilder.scala:35)
  at org.apache.spark.sql.internal.BaseSessionStateBuilder.build(BaseSessionStateBuilder.scala:289)
  at org.apache.spark.sql.SparkSession$.org$apache$spark$sql$SparkSession$$instantiateSessionState(SparkSession.scala:1050)
  ... 61 more
Caused by: java.lang.RuntimeException: java.net.ConnectException: Call From anthony-air.local/169.254.89.73 to localhost:8020 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused
  at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:522)
  at org.apache.spark.sql.hive.client.HiveClientImpl.<init>(HiveClientImpl.scala:191)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at org.apache.spark.sql.hive.client.IsolatedClientLoader.createClient(IsolatedClientLoader.scala:264)
  at org.apache.spark.sql.hive.HiveUtils$.newClientForMetadata(HiveUtils.scala:362)
  at org.apache.spark.sql.hive.HiveUtils$.newClientForMetadata(HiveUtils.scala:266)
  at org.apache.spark.sql.hive.HiveExternalCatalog.client$lzycompute(HiveExternalCatalog.scala:66)
  at org.apache.spark.sql.hive.HiveExternalCatalog.client(HiveExternalCatalog.scala:65)
  at org.apache.spark.sql.hive.HiveExternalCatalog$$anonfun$databaseExists$1.apply$mcZ$sp(HiveExternalCatalog.scala:194)
  at org.apache.spark.sql.hive.HiveExternalCatalog$$anonfun$databaseExists$1.apply(HiveExternalCatalog.scala:194)
  at org.apache.spark.sql.hive.HiveExternalCatalog$$anonfun$databaseExists$1.apply(HiveExternalCatalog.scala:194)
  at org.apache.spark.sql.hive.HiveExternalCatalog.withClient(HiveExternalCatalog.scala:97)
  ... 70 more
Caused by: java.net.ConnectException: Call From anthony-air.local/169.254.89.73 to localhost:8020 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at org.apache.hadoop.net.NetUtils.wrapWithMessage(NetUtils.java:791)
  at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:731)
  at org.apache.hadoop.ipc.Client.call(Client.java:1475)
  at org.apache.hadoop.ipc.Client.call(Client.java:1408)
  at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:230)
  at com.sun.proxy.$Proxy21.getFileInfo(Unknown Source)
  at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getFileInfo(ClientNamenodeProtocolTranslatorPB.java:757)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:256)
  at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:104)
  at com.sun.proxy.$Proxy22.getFileInfo(Unknown Source)
  at org.apache.hadoop.hdfs.DFSClient.getFileInfo(DFSClient.java:2102)
  at org.apache.hadoop.hdfs.DistributedFileSystem$19.doCall(DistributedFileSystem.java:1215)
  at org.apache.hadoop.hdfs.DistributedFileSystem$19.doCall(DistributedFileSystem.java:1211)
  at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
  at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1211)
  at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1412)
  at org.apache.hadoop.hive.ql.session.SessionState.createRootHDFSDir(SessionState.java:596)
  at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:554)
  at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:508)
  ... 84 more
Caused by: java.net.ConnectException: Connection refused
  at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
  at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
  at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:530)
  at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:494)
  at org.apache.hadoop.ipc.Client$Connection.setupConnection(Client.java:614)
  at org.apache.hadoop.ipc.Client$Connection.setupIOstreams(Client.java:713)
  at org.apache.hadoop.ipc.Client$Connection.access$2900(Client.java:375)
  at org.apache.hadoop.ipc.Client.getConnection(Client.java:1524)
  at org.apache.hadoop.ipc.Client.call(Client.java:1447)
  ... 104 more
<console>:14: error: not found: value spark
       import spark.implicits._
              ^
<console>:14: error: not found: value spark
       import spark.sql
              ^
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 2.2.0
      /_/

Using Scala version 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_161)
Type in expressions to have them evaluated.
Type :help for more information.
解决方案

启动Hadoop
$ cd $HADOOP_HOME/sbin
$ ./stat-all-sh

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
基于extjs的.NET3.5控件Coolite 1.0.0.34580 (Preview预览版), *************************************************** * Version 1.0.0 升级日志 * *************************************************** 1. Renamed Coolite.Ext.Web project to Ext.Net 2. Renamed Coolite.Examples project to Ext.Net.Examples 3. Renamed Coolite.Ext.UX project to Ext.Net.UX 4. Renamed Coolite.EmbeddedResourceBuilder project to Ext.Net.ERB 5. Renamed Coolite.Utilities project to Ext.Net.Utilities 6. Renamed Coolite.Sandbox project to Ext.Net.Sandbox 7. Renamed Coolite.Toolkit.sln Visual Studio Solution file to Ext.Net.sln. 8. Renamed Coolite.Ext.Web Namespace to Ext.Net 9. Renamed Coolite.Utilities Namespace to Ext.Net.Utilities 10. Renamed Coolite.Ext.UX Namespace to Ext.Net.UX 11. Renamed root singleton "Ext" class to "X". Example (Old) if (!Ext.IsAjaxRequest) { } Ext.Msg.Alert("Title", "Message").Show(); Example (New) if (!X.IsAjaxRequest) { } X.Msg.Alert("Title", "Message").Show(); 12. Added new feature to get server-side Property values from client id Token strings. Example 13. Renamed WebControl class to ExtControl. As well, renamed Coolite.Ext.Web.WebControl.cs file to Ext.Net.ExtControl.cs. 14. Removed . Please use . 15. Removed . Please use . 16. Renamed AjaxMethod class to DirectMethod. 17. Renamed AjaxMethodAttribute to DirectMethodAttribute. Example (Old) [AjaxMethod] public void DoSomthing() { } Example (New) [DirectMethod] public void DoSomthing() { } 18. Renamed property to . 19. Removed . Please use . 20. Removed Adapter class 21. Removed ColorMenuItem class 22. Removed ComboMenuItem class 23. Removed DateFieldMenuItem class 24. Removed D
Not Using Commons Logging ................................................................... 12 Using SLF4J ............................................................................................ 13 Using Log4J ............................................................................................. 14 II. What’s New in Spring Framework 4.x .................................................................................... 16 3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .................................................................. 17 3.2. Removed Deprecated Packages and Methods .................................................... 17 3.3. Java 8 (as well as 6 and 7) ............................................................................... 17 3.4. Java EE 6 and 7 ............................................................................................... 18 3.5. Groovy Bean Definition DSL .............................................................................. 18 3.6. Core Container Improvements ............................................................................ 19 3.7. General Web Improvements ............................................................................... 19 3.8. WebSocket, SockJS, and STOMP Messaging ..................................................... 19 3.9. Testing Improvements ........................................................................................ 20 III. Core Technologies .............................................................................................................. 21 4. The IoC container ........................................................................................................ 22 4.1. Introduction to the Spring IoC container and beans .............................................. 22 4.2. Container overview ............................................................................................ 22 Configuration metadata ..................................................................................... 23 Instantiating a container .................................................................................... 24 Composing XML-based configuration metadata .......................................... 25 Using the container .......................................................................................... 26 4.3. Bean overview ................................................................................................... 27 Naming beans .................................................................................................. 28 Aliasing a bean outside the bean definition ................................................ 28 Instantiating beans ........................................................................................... 29 Instantiation with a constructor .................................................................. 29 Instantiation with a static factory method .................................................... 30 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation iii Instantiation using an instance factory method ........................................... 30 4.4. Dependencies ................................................................................................... 32 Dependency injection ....................................................................................... 32 Constructor-based dependency injection .................................................... 32 Setter-based dependency injection ............................................................ 34 Dependency resolution process ................................................................. 35 Examples of dependency injection ............................................................. 36 Dependencies and configuration in detail ........................................................... 38 Straight values (primitives, Strings, and so on) ........................................... 38 References to other beans (collaborators) .................................................. 40 Inner beans .............................................................................................. 41 Collections ............................................................................................... 41 Null and empty string values ..................................................................... 44 XML shortcut with the p-namespace .......................................................... 44 XML shortcut with the c-namespace .......................................................... 46 Compound property names ....................................................................... 46 Using depends-on ............................................................................................ 47 Lazy-initialized beans ....................................................................................... 47 Autowiring collaborators .................................................................................... 48 Limitations and disadvantages of autowiring ............................................... 49 Excluding a bean from autowiring .............................................................. 50 Method injection ............................................................................................... 50 Lookup method injection ........................................................................... 51 Arbitrary method replacement ................................................................... 53 4.5. Bean scopes ..................................................................................................... 54 The singleton scope ......................................................................................... 55 The prototype scope ......................................................................................... 55 Singleton beans with prototype-bean dependencies ............................................ 56 Request, session, and global session scopes .................................................... 56 Initial web configuration ............................................................................ 57 Request scope ......................................................................................... 58 Session scope .......................................................................................... 58 Global session scope ............................................................................... 58 Scoped beans as dependencies ................................................................ 58 Custom scopes ................................................................................................ 60 Creating a custom scope .......................................................................... 60 Using a custom scope .............................................................................. 61 4.6. Customizing the nature of a bean ....................................................................... 62 Lifecycle callbacks ............................................................................................ 62 Initialization callbacks ............................................................................... 63 Destruction callbacks ................................................................................ 64 Default initialization and destroy methods .................................................. 64 Combining lifecycle mechanisms ............................................................... 66 Startup and shutdown callbacks ................................................................ 66 Shutting down the Spring IoC container gracefully in non-web applications ................................................................................................................. 68 ApplicationContextAware and BeanNameAware ................................................. 68 Other Aware interfaces ..................................................................................... 69 4.7. Bean definition inheritance ................................................................................. 71 4.8. Container Extension Points ................................................................................ 72 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation iv Customizing beans using a BeanPostProcessor ................................................. 72 Example: Hello World, BeanPostProcessor-style ........................................ 74 Example: The RequiredAnnotationBeanPostProcessor ............................... 75 Customizing configuration metadata with a BeanFactoryPostProcessor ................ 75 Example: the Class name substitution PropertyPlaceholderConfigurer .......... 76 Example: the PropertyOverrideConfigurer .................................................. 77 Customizing instantiation logic with a FactoryBean ............................................. 78 4.9. Annotation-based container configuration ............................................................ 79 @Required ....................................................................................................... 80 @Autowired ..................................................................................................... 80 Fine-tuning annotation-based autowiring with qualifiers ....................................... 83 Using generics as autowiring qualifiers .............................................................. 89 CustomAutowireConfigurer ................................................................................ 90 @Resource ...................................................................................................... 90 @PostConstruct and @PreDestroy .................................................................... 92 4.10. Classpath scanning and managed components ................................................. 92 @Component and further stereotype annotations ............................................... 93 Meta-annotations .............................................................................................. 93 Automatically detecting classes and registering bean definitions .......................... 94 Using filters to customize scanning ................................................................... 95 Defining bean metadata within components ....................................................... 96 Naming autodetected components ..................................................................... 97 Providing a scope for autodetected components ................................................ 98 Providing qualifier metadata with annotations ..................................................... 99 4.11. Using JSR 330 Standard Annotations ............................................................... 99 Dependency Injection with @Inject and @Named ............................................. 100 @Named: a standard equivalent to the @Component annotation ....................... 100 Limitations of the standard approach ............................................................... 101 4.12. Java-based container configuration ................................................................. 102 Basic concepts: @Bean and @Configuration ................................................... 102 Instantiating the Spring container using AnnotationConfigApplicationContext ....... 103 Simple construction ................................................................................ 103 Building the container programmatically using register(Class<?>…) ........... 104 Enabling component scanning with scan(String…) .................................... 104 Support for web applications with AnnotationConfigWebApplicationContext ............................................................................................................... 105 Using the @Bean annotation .......................................................................... 106 Declaring a bean .................................................................................... 107 Receiving lifecycle callbacks ................................................................... 107 Specifying bean scope ............................................................................ 108 Customizing bean naming ....................................................................... 109 Bean aliasing ......................................................................................... 109 Bean description ..................................................................................... 110 Using the @Configuration annotation ............................................................... 110 Injecting inter-bean dependencies ............................................................ 110 Lookup method injection ......................................................................... 111 Further information about how Java-based configuration works internally .... 111 Composing Java-based configurations ............................................................. 112 Using the @Import annotation ................................................................. 112 Conditionally including @Configuration classes or @Beans ....................... 116 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation v Combining Java and XML configuration ................................................... 117 4.13. Bean definition profiles and environment abstraction ........................................ 120 4.14. PropertySource Abstraction ............................................................................ 120 4.15. Registering a LoadTimeWeaver ...................................................................... 120 4.16. Additional Capabilities of the ApplicationContext .............................................. 120 Internationalization using MessageSource ........................................................ 121 Standard and Custom Events .......................................................................... 124 Convenient access to low-level resources ........................................................ 127 Convenient ApplicationContext instantiation for web applications ....................... 128 Deploying a Spring ApplicationContext as a J2EE RAR file ............................... 128 4.17. The BeanFactory ........................................................................................... 129 BeanFactory or ApplicationContext? ................................................................ 129 Glue code and the evil singleton ..................................................................... 131 5. Resources .................................................................................................................. 132 5.1. Introduction ..................................................................................................... 132 5.2. The Resource interface .................................................................................... 132 5.3. Built-in Resource implementations .................................................................... 133 UrlResource ................................................................................................... 133 ClassPathResource ........................................................................................ 133 FileSystemResource ....................................................................................... 134 ServletContextResource .................................................................................. 134 InputStreamResource ..................................................................................... 134 ByteArrayResource ......................................................................................... 134 5.4. The ResourceLoader ....................................................................................... 134 5.5. The ResourceLoaderAware interface ................................................................ 135 5.6. Resources as dependencies ............................................................................. 136 5.7. Application contexts and Resource paths .......................................................... 137 Constructing application contexts ..................................................................... 137 Constructing ClassPathXmlApplicationContext instances - shortcuts .......... 137 Wildcards in application context constructor resource paths ............................... 138 Ant-style Patterns ................................................................................... 138 The Classpath*: portability classpath*: prefix ............................................ 139 Other notes relating to wildcards ............................................................. 139 FileSystemResource caveats .......................................................................... 140 6. Validation, Data Binding, and Type Conversion ............................................................ 141 6.1. Introduction ..................................................................................................... 141 6.2. Validation using Spring’s Validator interface ...................................................... 141 6.3. Resolving codes to error messages .................................................................. 143 6.4. Bean manipulation and the BeanWrapper ......................................................... 144 Setting and getting basic and nested properties ............................................... 144 Built-in PropertyEditor implementations ............................................................ 146 Registering additional custom PropertyEditors .......................................... 149 6.5. Spring Type Conversion ................................................................................... 151 Converter SPI ................................................................................................ 151 ConverterFactory ............................................................................................ 152 GenericConverter ........................................................................................... 153 ConditionalGenericConverter ................................................................... 154 ConversionService API ................................................................................... 154 Configuring a ConversionService ..................................................................... 154 Using a ConversionService programmatically ................................................... 155 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation vi 6.6. Spring Field Formatting .................................................................................... 155 Formatter SPI ................................................................................................. 156 Annotation-driven Formatting ........................................................................... 157 Format Annotation API ............................................................................ 158 FormatterRegistry SPI ..................................................................................... 159 FormatterRegistrar SPI ................................................................................... 159 Configuring Formatting in Spring MVC ............................................................. 159 6.7. Configuring a global date & time format ............................................................ 161 6.8. Spring Validation ............................................................................................. 163 Overview of the JSR-303 Bean Validation API ................................................. 163 Configuring a Bean Validation Provider ............................................................ 164 Injecting a Validator ................................................................................ 164 Configuring Custom Constraints .............................................................. 164 Additional Configuration Options .............................................................. 165 Configuring a DataBinder ................................................................................ 165 Spring MVC 3 Validation ................................................................................. 166 Triggering @Controller Input Validation .................................................... 166 Configuring a Validator for use by Spring MVC ......................................... 166 Configuring a JSR-303/JSR-349 Validator for use by Spring MVC .............. 167 7. Spring Expression Language (SpEL) ........................................................................... 168 7.1. Introduction ..................................................................................................... 168 7.2. Feature Overview ............................................................................................ 168 7.3. Expression Evaluation using Spring’s Expression Interface ................................. 169 The EvaluationContext interface ...................................................................... 171 Type Conversion .................................................................................... 171 7.4. Expression support for defining bean definitions ................................................ 172 XML based configuration ................................................................................ 172 Annotation-based configuration ........................................................................ 173 7.5. Language Reference ........................................................................................ 174 Literal expressions .......................................................................................... 174 Properties, Arrays, Lists, Maps, Indexers ......................................................... 174 Inline lists ....................................................................................................... 175 Array construction ........................................................................................... 175 Methods ......................................................................................................... 176 Operators ....................................................................................................... 176 Relational operators ................................................................................ 176 Logical operators .................................................................................... 177 Mathematical operators ........................................................................... 177 Assignment .................................................................................................... 178 Types ............................................................................................................. 178 Constructors ................................................................................................... 179 Variables ........................................................................................................ 179 The #this and #root variables .................................................................. 179 Functions ....................................................................................................... 180 Bean references ............................................................................................. 180 Ternary Operator (If-Then-Else) ....................................................................... 180 The Elvis Operator ......................................................................................... 181 Safe Navigation operator ................................................................................ 181 Collection Selection ........................................................................................ 182 Collection Projection ....................................................................................... 182 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation vii Expression templating ..................................................................................... 183 7.6. Classes used in the examples .......................................................................... 183 8. Aspect Oriented Programming with Spring ................................................................... 187 8.1. Introduction ..................................................................................................... 187 AOP concepts ................................................................................................ 187 Spring AOP capabilities and goals ................................................................... 189 AOP Proxies .................................................................................................. 190 8.2. @AspectJ support ........................................................................................... 190 Enabling @AspectJ Support ............................................................................ 190 Enabling @AspectJ Support with Java configuration ................................. 190 Enabling @AspectJ Support with XML configuration ................................. 191 Declaring an aspect ........................................................................................ 191 Declaring a pointcut ........................................................................................ 192 Supported Pointcut Designators .............................................................. 192 Combining pointcut expressions .............................................................. 194 Sharing common pointcut definitions ........................................................ 194 Examples ............................................................................................... 196 Writing good pointcuts ............................................................................ 198 Declaring advice ............................................................................................. 199 Before advice ......................................................................................... 199 After returning advice .............................................................................. 200 After throwing advice .............................................................................. 200 After (finally) advice ................................................................................ 201 Around advice ........................................................................................ 202 Advice parameters .................................................................................. 203 Advice ordering ...................................................................................... 206 Introductions ................................................................................................... 206 Aspect instantiation models ............................................................................. 207 Example ......................................................................................................... 208 8.3. Schema-based AOP support ............................................................................ 209 Declaring an aspect ........................................................................................ 210 Declaring a pointcut ........................................................................................ 210 Declaring advice ............................................................................................. 212 Before advice ......................................................................................... 212 After returning advice .............................................................................. 212 After throwing advice .............................................................................. 213 After (finally) advice ................................................................................ 214 Around advice ........................................................................................ 214 Advice parameters .................................................................................. 215 Advice ordering ...................................................................................... 216 Introductions ................................................................................................... 217 Aspect instantiation models ............................................................................. 217 Advisors ......................................................................................................... 217 Example ......................................................................................................... 218 8.4. Choosing which AOP declaration style to use .................................................... 220 Spring AOP or full AspectJ? ........................................................................... 220 @AspectJ or XML for Spring AOP? ................................................................. 221 8.5. Mixing aspect types ......................................................................................... 222 8.6. Proxying mechanisms ...................................................................................... 222 Understanding AOP proxies ............................................................................ 223 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation viii 8.7. Programmatic creation of @AspectJ Proxies ..................................................... 225 8.8. Using AspectJ with Spring applications ............................................................. 225 Using AspectJ to dependency inject domain objects with Spring ........................ 226 Unit testing @Configurable objects .......................................................... 228 Working with multiple application contexts ................................................ 228 Other Spring aspects for AspectJ .................................................................... 229 Configuring AspectJ aspects using Spring IoC ................................................. 229 Load-time weaving with AspectJ in the Spring Framework ................................. 230 A first example ....................................................................................... 231 Aspects .................................................................................................. 234 ' META-INF/aop.xml' ............................................................................... 234 Required libraries (JARS) ........................................................................ 234 Spring configuration ................................................................................ 235 Environment-specific configuration ........................................................... 237 8.9. Further Resources ........................................................................................... 239 9. Spring AOP APIs ....................................................................................................... 240 9.1. Introduction ..................................................................................................... 240 9.2. Pointcut API in Spring ...................................................................................... 240 Concepts ........................................................................................................ 240 Operations on pointcuts .................................................................................. 241 AspectJ expression pointcuts .......................................................................... 241 Convenience pointcut implementations ............................................................ 241 Static pointcuts ....................................................................................... 241 Dynamic pointcuts .................................................................................. 242 Pointcut superclasses ..................................................................................... 243 Custom pointcuts ............................................................................................ 243 9.3. Advice API in Spring ........................................................................................ 243 Advice lifecycles ............................................................................................. 243 Advice types in Spring .................................................................................... 244 Interception around advice ...................................................................... 244 Before advice ......................................................................................... 244 Throws advice ........................................................................................ 245 After Returning advice ............................................................................ 246 Introduction advice .................................................................................. 247 9.4. Advisor API in Spring ....................................................................................... 249 9.5. Using the ProxyFactoryBean to create AOP proxies ........................................... 250 Basics ............................................................................................................ 250 JavaBean properties ....................................................................................... 250 JDK- and CGLIB-based proxies ...................................................................... 251 Proxying interfaces ......................................................................................... 252 Proxying classes ............................................................................................ 254 Using global advisors ...................................................................................... 255 9.6. Concise proxy definitions ................................................................................. 255 9.7. Creating AOP proxies programmatically with the ProxyFactory ............................ 256 9.8. Manipulating advised objects ............................................................................ 257 9.9. Using the "auto-proxy" facility ........................................................................... 258 Autoproxy bean definitions .............................................................................. 258 BeanNameAutoProxyCreator ................................................................... 259 DefaultAdvisorAutoProxyCreator .............................................................. 259 AbstractAdvisorAutoProxyCreator ............................................................ 260 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation ix Using metadata-driven auto-proxying ............................................................... 260 9.10. Using TargetSources ...................................................................................... 262 Hot swappable target sources ......................................................................... 263 Pooling target sources .................................................................................... 263 Prototype target sources ................................................................................. 265 ThreadLocal target sources ............................................................................. 265 9.11. Defining new Advice types ............................................................................. 265 9.12. Further resources ........................................................................................... 266 10. Testing ..................................................................................................................... 267 10.1. Introduction to Spring Testing ......................................................................... 267 10.2. Unit Testing ................................................................................................... 267 Mock Objects ................................................................................................. 267 Environment ........................................................................................... 267 JNDI ...................................................................................................... 267 Servlet API ............................................................................................. 267 Portlet API ............................................................................................. 268 Unit Testing support Classes .......................................................................... 268 General utilities ...................................................................................... 268 Spring MVC ........................................................................................... 268 10.3. Integration Testing ......................................................................................... 268 Overview ........................................................................................................ 268 Goals of Integration Testing ............................................................................ 269 Context management and caching ........................................................... 269 Dependency Injection of test fixtures ....................................................... 269 Transaction management ........................................................................ 270 Support classes for integration testing ..................................................... 270 JDBC Testing Support .................................................................................... 271 Annotations .................................................................................................... 271 Spring Testing Annotations ..................................................................... 271 Standard Annotation Support .................................................................. 276 Spring JUnit Testing Annotations ............................................................. 277 Meta-Annotation Support for Testing ........................................................ 278 Spring TestContext Framework ....................................................................... 279 Key abstractions ..................................................................................... 280 Context management .............................................................................. 281 Dependency injection of test fixtures ........................................................ 297 Testing request and session scoped beans .............................................. 299 Transaction management ........................................................................ 301 TestContext Framework support classes .................................................. 304 Spring MVC Test Framework .......................................................................... 306 Server-Side Tests ................................................................................... 306 Client-Side REST Tests .......................................................................... 312 PetClinic Example .......................................................................................... 313 10.4. Further Resources ......................................................................................... 314 IV. Data Access ..................................................................................................................... 316 11. Transaction Management .......................................................................................... 317 11.1. Introduction to Spring Framework transaction management .............................. 317 11.2. Advantages of the Spring Framework’s transaction support model ..................... 317 Global transactions ......................................................................................... 317 Local transactions ........................................................................................... 318 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation x Spring Framework’s consistent programming model ......................................... 318 11.3. Understanding the Spring Framework transaction abstraction ............................ 319 11.4. Synchronizing resources with transactions ....................................................... 323 High-level synchronization approach ................................................................ 323 Low-level synchronization approach ................................................................. 323 TransactionAwareDataSourceProxy ................................................................. 324 11.5. Declarative transaction management ............................................................... 324 Understanding the Spring Framework’s declarative transaction implementation ... 325 Example of declarative transaction implementation ........................................... 326 Rolling back a declarative transaction .............................................................. 330 Configuring different transactional semantics for different beans ........................ 331 <tx:advice/> settings ....................................................................................... 333 Using @Transactional ..................................................................................... 335 @Transactional settings .......................................................................... 339 Multiple Transaction Managers with @Transactional ................................. 340 Custom shortcut annotations ................................................................... 341 Transaction propagation .................................................................................. 341 Required ................................................................................................ 342 RequiresNew .......................................................................................... 342 Nested ................................................................................................... 343 Advising transactional operations ..................................................................... 343 Using @Transactional with AspectJ ................................................................. 346 11.6. Programmatic transaction management ........................................................... 347 Using the TransactionTemplate ....................................................................... 347 Specifying transaction settings ................................................................ 349 Using the PlatformTransactionManager ............................................................ 349 11.7. Choosing between programmatic and declarative transaction management ........ 350 11.8. Application server-specific integration .............................................................. 350 IBM WebSphere ............................................................................................. 351 Oracle WebLogic Server ................................................................................. 351 11.9. Solutions to common problems ....................................................................... 351 Use of the wrong transaction manager for a specific DataSource ....................... 351 11.10. Further Resources ....................................................................................... 351 12. DAO support ............................................................................................................ 352 12.1. Introduction .................................................................................................... 352 12.2. Consistent exception hierarchy ....................................................................... 352 12.3. Annotations used for configuring DAO or Repository classes ............................ 353 13. Data access with JDBC ............................................................................................ 355 13.1. Introduction to Spring Framework JDBC .......................................................... 355 Choosing an approach for JDBC database access ........................................... 355 Package hierarchy .......................................................................................... 356 13.2. Using the JDBC core classes to control basic JDBC processing and error handling ................................................................................................................. 357 JdbcTemplate ................................................................................................. 357 Examples of JdbcTemplate class usage ................................................... 357 JdbcTemplate best practices ................................................................... 359 NamedParameterJdbcTemplate ....................................................................... 361 SQLExceptionTranslator .................................................................................. 363 Executing statements ...................................................................................... 365 Running queries ............................................................................................. 365 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation xi Updating the database .................................................................................... 366 Retrieving auto-generated keys ....................................................................... 367 13.3. Controlling database connections .................................................................... 367 DataSource .................................................................................................... 367 DataSourceUtils .............................................................................................. 369 SmartDataSource ........................................................................................... 369 AbstractDataSource ........................................................................................ 369 SingleConnectionDataSource .......................................................................... 369 DriverManagerDataSource .............................................................................. 369 TransactionAwareDataSourceProxy ................................................................. 370 DataSourceTransactionManager ...................................................................... 370 NativeJdbcExtractor ........................................................................................ 370 13.4. JDBC batch operations .................................................................................. 371 Basic batch operations with the JdbcTemplate ................................................. 371 Batch operations with a List of objects ............................................................. 372 Batch operations with multiple batches ............................................................ 373 13.5. Simplifying JDBC operations with the SimpleJdbc classes ................................ 374 Inserting data using SimpleJdbcInsert .............................................................. 374 Retrieving auto-generated keys using SimpleJdbcInsert .................................... 375 Specifying columns for a SimpleJdbcInsert ...................................................... 376 Using SqlParameterSource to provide parameter values ................................... 376 Calling a stored procedure with SimpleJdbcCall ............................................... 377 Explicitly declaring parameters to use for a SimpleJdbcCall ............................... 379 How to define SqlParameters .......................................................................... 380 Calling a stored function using SimpleJdbcCall ................................................. 381 Returning ResultSet/REF Cursor from a SimpleJdbcCall ................................... 381 13.6. Modeling JDBC operations as Java objects ..................................................... 382 SqlQuery ........................................................................................................ 383 MappingSqlQuery ........................................................................................... 383 SqlUpdate ...................................................................................................... 384 StoredProcedure ............................................................................................. 385 13.7. Common problems with parameter and data value handling .............................. 388 Providing SQL type information for parameters ................................................. 389 Handling BLOB and CLOB objects .................................................................. 389 Passing in lists of values for IN clause ............................................................ 390 Handling complex types for stored procedure calls ........................................... 391 13.8. Embedded database support .......................................................................... 392 Why use an embedded database? .................................................................. 392 Creating an embedded database instance using Spring XML ............................ 392 Creating an embedded database instance programmatically .............................. 392 Extending the embedded database support ...................................................... 393 Using HSQL ................................................................................................... 393 Using H2 ........................................................................................................ 393 Using Derby ................................................................................................... 393 Testing data access logic with an embedded database ..................................... 393 13.9. Initializing a DataSource ................................................................................. 394 Initializing a database instance using Spring XML ............................................. 394 Initialization of Other Components that Depend on the Database ............... 395 14. Object Relational Mapping (ORM) Data Access .......................................................... 397 14.1. Introduction to ORM with Spring ..................................................................... 397 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation xii 14.2. General ORM integration considerations ......................................................... 398 Resource and transaction management ........................................................... 398 Exception translation ....................................................................................... 399 14.3. Hibernate ....................................................................................................... 399 SessionFactory setup in a Spring container ...................................................... 400 Implementing DAOs based on plain Hibernate 3 API ........................................ 400 Declarative transaction demarcation ................................................................ 402 Programmatic transaction demarcation ............................................................ 404 Transaction management strategies ................................................................ 405 Comparing container-managed and locally defined resources ............................ 407 Spurious application server warnings with Hibernate ......................................... 408 14.4. JDO .............................................................................................................. 409 PersistenceManagerFactory setup ................................................................... 409 Implementing DAOs based on the plain JDO API ............................................. 410 Transaction management ................................................................................ 412 JdoDialect ...................................................................................................... 413 14.5. JPA ............................................................................................................... 414 Three options for JPA setup in a Spring environment ........................................ 414 LocalEntityManagerFactoryBean .............................................................. 414 Obtaining an EntityManagerFactory from JNDI ......................................... 415 LocalContainerEntityManagerFactoryBean ............................................... 415 Dealing with multiple persistence units ..................................................... 417 Implementing DAOs based on plain JPA .......................................................... 418 Transaction Management ................................................................................ 420 JpaDialect ...................................................................................................... 421 15. Marshalling XML using O/X Mappers ......................................................................... 423 15.1. Introduction .................................................................................................... 423 Ease of configuration ...................................................................................... 423 Consistent Interfaces ...................................................................................... 423 Consistent Exception Hierarchy ....................................................................... 423 15.2. Marshaller and Unmarshaller .......................................................................... 423 Marshaller ...................................................................................................... 423 Unmarshaller .................................................................................................. 424 XmlMappingException ..................................................................................... 425 15.3. Using Marshaller and Unmarshaller ................................................................. 425 15.4. XML Schema-based Configuration .................................................................. 427 15.5. JAXB ............................................................................................................. 427 Jaxb2Marshaller ............................................................................................. 428 XML Schema-based Configuration ........................................................... 428 15.6. Castor ........................................................................................................... 429 CastorMarshaller ............................................................................................ 429 Mapping ......................................................................................................... 429 XML Schema-based Configuration ........................................................... 429 15.7. XMLBeans ..................................................................................................... 430 XmlBeansMarshaller ....................................................................................... 430 XML Schema-based Configuration ........................................................... 430 15.8. JiBX .............................................................................................................. 431 JibxMarshaller ................................................................................................ 431 XML Schema-based Configuration ........................................................... 431 15.9. XStream ........................................................................................................ 432 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation xiii XStreamMarshaller ......................................................................................... 432 V. The Web ........................................................................................................................... 434 16. Web MVC framework ................................................................................................ 435 16.1. Introduction to Spring Web MVC framework .................................................... 435 Features of Spring Web MVC ......................................................................... 436 Pluggability of other MVC implementations ...................................................... 437 16.2. The DispatcherServlet .................................................................................... 437 Special Bean Types In the WebApplicationContext ........................................... 440 Default DispatcherServlet Configuration ........................................................... 441 DispatcherServlet Processing Sequence .......................................................... 441 16.3. Implementing Controllers ................................................................................ 443 Defining a controller with @Controller .............................................................. 443 Mapping Requests With Using @RequestMapping ........................................... 444 New Support Classes for @RequestMapping methods in Spring MVC 3.1 .. 446 URI Template Patterns ........................................................................... 447 URI Template Patterns with Regular Expressions ..................................... 448 Path Patterns ......................................................................................... 449 Patterns with Placeholders ...................................................................... 449 Matrix Variables ...................................................................................... 449 Consumable Media Types ....................................................................... 450 Producible Media Types .......................................................................... 451 Request Parameters and Header Values ................................................. 451 Defining @RequestMapping handler methods .................................................. 452 Supported method argument types .......................................................... 452 Supported method return types ............................................................... 454 Binding request parameters to method parameters with @RequestParam ... 455 Mapping the request body with the @RequestBody annotation .................. 456 Mapping the response body with the @ResponseBody annotation ............. 457 Creating REST Controllers with the @RestController annotation ................ 457 Using HttpEntity ...................................................................................... 457 Using @ModelAttribute on a method ....................................................... 458 Using @ModelAttribute on a method argument ......................................... 459 Using @SessionAttributes to store model attributes in the HTTP session between requests ................................................................................... 461 Specifying redirect and flash attributes ..................................................... 461 Working with "application/x-www-form-urlencoded" data ............................ 462 Mapping cookie values with the @CookieValue annotation ........................ 462 Mapping request header attributes with the @RequestHeader annotation ... 463 Method Parameters And Type Conversion ............................................... 463 Customizing WebDataBinder initialization ................................................. 464 Support for the Last-Modified Response Header To Facilitate Content Caching ................................................................................................. 465 Assisting Controllers with the @ControllerAdvice annotation ...................... 465 Asynchronous Request Processing .................................................................. 466 Exception Handling for Async Requests ................................................... 467 Intercepting Async Requests ................................................................... 467 Configuration for Async Request Processing ............................................ 468 Testing Controllers ......................................................................................... 469 16.4. Handler mappings .......................................................................................... 469 Intercepting requests with a HandlerInterceptor ................................................ 469 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation xiv 16.5. Resolving views ............................................................................................. 471 Resolving views with the ViewResolver interface .............................................. 471 Chaining ViewResolvers ................................................................................. 473 Redirecting to views ....................................................................................... 474 RedirectView .......................................................................................... 474 The redirect: prefix ................................................................................. 475 The forward: prefix ................................................................................. 475 ContentNegotiatingViewResolver ..................................................................... 475 16.6. Using flash attributes ..................................................................................... 478 16.7. Building URIs ................................................................................................. 479 16.8. Building URIs to Controllers and methods ....................................................... 480 16.9. Using locales ................................................................................................. 480 Obtaining Time Zone Information .................................................................... 481 AcceptHeaderLocaleResolver .......................................................................... 481 CookieLocaleResolver ..................................................................................... 481 SessionLocaleResolver ................................................................................... 481 LocaleChangeInterceptor ................................................................................ 482 16.10. Using themes ............................................................................................... 482 Overview of themes ........................................................................................ 482 Defining themes ............................................................................................. 482 Theme resolvers ............................................................................................. 483 16.11. Spring’s multipart (file upload) support ........................................................... 483 Introduction .................................................................................................... 483 Using a MultipartResolver with Commons FileUpload ........................................ 484 Using a MultipartResolver with Servlet 3.0 ....................................................... 484 Handling a file upload in a form ...................................................................... 484 Handling a file upload request from programmatic clients .................................. 486 16.12. Handling exceptions ..................................................................................... 486 HandlerExceptionResolver ............
This package contains 3 kid: 1. a book Developing Flex Applications 2. a web page viewer for doc88 ebt 3. a DDA downloader for doc88.com CONTENTS PART I: Presenting Flex CHAPTER 1: Introducing Flex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 About Flex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Developing applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Where to next. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 CHAPTER 2: Using MXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 About MXML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 The relationship between MXML and ActionScript classes. . . . . . . . . . . . . . . . . . 37 How MXML relates to standards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 CHAPTER 3: Using ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 About ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Using ActionScript in Flex applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 CHAPTER 4: Developing Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 About the Flex coding process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Working with a multitier application model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Controlling the appearance of an application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Enabling application zooming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Separating ActionScript from MXML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 About the Flex development environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Using Flex development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Architecting an application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Improving application start-up time and performance. . . . . . . . . . . . . . . . . . . . . . 78 Summary of Flex application features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 4Contents PART II: Building User Interfaces to Flex Applications CHAPTER 5: Using Flex Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 About components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Class hierarchy for components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Using styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Using behaviors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Handling events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Applying skins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Sizing components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Changing the appearance of a component at runtime . . . . . . . . . . . . . . . . . . . . . . 99 Extending components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 CHAPTER 6: Using Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 About controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Working with controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Button control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 CheckBox control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 DateChooser. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 DateField control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 HRule and VRule controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 HSlider and VSlider controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Label control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Link control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Loader control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 NumericStepper control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 ProgressBar control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 RadioButton control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 ScrollBar control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Text control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 TextArea control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 TextInput control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 CHAPTER 7: Using Data Provider Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 About data providers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 ComboBox control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 DataGrid control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 List control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Menu control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 MenuBar control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Tree control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Contents5 CHAPTER 8: Introducing Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 About containers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Using containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Controlling component sizing and positioning in a container. . . . . . . . . . . . . . . 246 Using scroll bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Creating component instances at runtime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 Configuring containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 CHAPTER 9: Using the Application Container . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Using the Application container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Application container syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 Showing the download progress of an application . . . . . . . . . . . . . . . . . . . . . . . . 274 CHAPTER 10 : Using Layout Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 About layout containers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Canvas layout container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Box layout container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 ControlBar layout container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 DividedBox layout container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Form layout container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 Grid layout container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Panel layout container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 Tile layout container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 TitleWindow layout container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 CHAPTER 11 : Using Navigator Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 About navigator containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 ViewStack navigator container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 LinkBar navigator container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 TabNavigator container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 TabBar navigator container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338 Accordion navigator container. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 CHAPTER 12 : Dynamically Repeating Controls and Containers . . . . . . . . . . . . 351 Using a Repeater object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 Dynamically creating components based on data type. . . . . . . . . . . . . . . . . . . . . 359 How a Repeater object executes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 CHAPTER 13 : Importing Images and Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 Importing images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 Controlling image importing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 Using media controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 6Contents PART III: Improving User Experience CHAPTER 14 : Building an Application with Multiple MXML Files . . . . . . . . . . . 383 About MXML components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 Creating MXML components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385 Passing component references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390 Using interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391 CHAPTER 15 : Working with ActionScript in Flex . . . . . . . . . . . . . . . . . . . . . . . . 393 Using ActionScript in Flex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 Working with components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 About scope. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 Changing the appearance of a component at runtime . . . . . . . . . . . . . . . . . . . . . 407 Importing external resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408 Using the doLater() method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 CHAPTER 16 : Using Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 About events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Handling events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 Handling mouse events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431 Using base class events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 CHAPTER 17 : Creating ActionScript Components . . . . . . . . . . . . . . . . . . . . . . . 437 About ActionScript components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 Defining custom user-interface components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 Passing data to a custom tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 Defining events in ActionScript components. . . . . . . . . . . . . . . . . . . . . . . . . . . . 440 Adding ActionScript components to the Flex environment. . . . . . . . . . . . . . . . . 441 Defining nonvisual components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442 CHAPTER 18 : Creating Cell Renderers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 Creating a cell renderer class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 CHAPTER 19 : Using Styles, Fonts, and Themes . . . . . . . . . . . . . . . . . . . . . . . . 455 About styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 Using external style sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474 Using local style definitions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 Using the StyleManager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479 Using the setStyle() and getStyle() methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482 Using inline styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 About fonts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 Using themes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 Skinning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 Contents7 CHAPTER 20 : Using Behaviors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 Applying behaviors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 Customizing an effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 Defining a custom effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 Defining and playing an effect in ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . 512 Using a custom effect trigger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514 CHAPTER 21 : Using ToolTips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517 About ToolTips. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517 Using ToolTips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518 Using the ToolTipManager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521 CHAPTER 22 : Using the Cursor Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 About the Cursor Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 Cursor Manager syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 CHAPTER 23 : Using the Drag and Drop Manager . . . . . . . . . . . . . . . . . . . . . . . 531 About the Drag and Drop Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531 Using a List, Tree, or DataGrid control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 Drag and Drop Manager syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 CHAPTER 24 : Using the History Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549 About history management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549 Using standard history management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549 Using custom history management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551 How the HistoryManager class saves and loads state . . . . . . . . . . . . . . . . . . . . . . 554 Using history management in a custom HTML file . . . . . . . . . . . . . . . . . . . . . . 555 CHAPTER 25 : Applying Deferred Instantiation . . . . . . . . . . . . . . . . . . . . . . . . . 557 About deferred instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557 Using deferred instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558 Manually instantiating controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562 Using the childDescriptors property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564 Starting applications incrementally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 CHAPTER 26 : Printing from SWF Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571 About Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571 Printing from the Flash Player context menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . 572 Using the ActionScript PrintJob class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573 Starting a print job . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576 8Contents PART IV: Data Access and Interconnectivity CHAPTER 27 : Creating Accessible Applications . . . . . . . . . . . . . . . . . . . . . . . . 583 Accessibility overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583 About screen reader technology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585 Configuring Flex applications for accessibility. . . . . . . . . . . . . . . . . . . . . . . . . . . 585 Using accessible components and managers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587 Creating tab order and reading order. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589 Accessibility for hearing-impaired users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591 Testing accessible content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591 CHAPTER 28 : Managing Data in Flex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 About Flex data management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 Comparing Flex data management to other technologies. . . . . . . . . . . . . . . . . . . 597 CHAPTER 29 : Binding and Storing Data in Flex . . . . . . . . . . . . . . . . . . . . . . . . 601 Binding data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601 Using data models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610 CHAPTER 30 : Validating Data in Flex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619 Validating data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619 Using standard validators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628 CHAPTER 31 : Formatting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639 Using formatters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639 Writing an error handler function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640 Using the standard formatters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640 Creating a custom formatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651 CHAPTER 32 : Using Data Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655 About data services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656 Declaring a data service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658 Calling a data service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659 Handling data service results. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666 Using a service with binding, validation, and event handlers. . . . . . . . . . . . . . . . 669 Handling asynchronous calls to data services. . . . . . . . . . . . . . . . . . . . . . . . . . . . 671 Using callback URLs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 Generating debugging information for data services . . . . . . . . . . . . . . . . . . . . . . 674 Securing data services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675 Working with web services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682 Working with remote object services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688 Data service tag properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695 Data service whitelist tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700 Contents9 PART V: Advanced Application Development and Debugging CHAPTER 33 : Debugging Flex Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 705 About debugging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705 Enabling debug and warning messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706 Using the error-reporting mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707 Supported errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710 About the debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712 Configuring the debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714 Invoking the debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715 Using the debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717 CHAPTER 34 : Profiling ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729 About profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729 About the Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730 Using the Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730 Analyzing data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739 CHAPTER 35 : Using the Flex JSP Tag Library . . . . . . . . . . . . . . . . . . . . . . . . . 741 Introduction to the Flex JSP tag library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741 Using the Flex JSP tag library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742 About the Flex tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742 Using the <mxml> tag. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745 Using the <flash> tag. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748 Using the <param> tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748 PART VI: Administrating Applications CHAPTER 36 : Administering Flex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753 Using the command-line compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754 Editing the flex-config.xml file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757 Changing application server settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767 Configuring logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 768 CHAPTER 37 : Applying Flex Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773 Flex security features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773 Flash Player security features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775 Security concerns of an open format technology . . . . . . . . . . . . . . . . . . . . . . . . . 782 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783 10 Contents CHAPTER 38 : Deploying Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785 About deploying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785 Adding Flex to your application server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 786 Distributing components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791 Working with Flex files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793 About the HTML wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798 Passing request data to Flex applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805 Flash Player detection and deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808 Managing Flash Player auto-update. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812 PART VII: Custom Components CHAPTER 39 : Working with Flash MX 2004 . . . . . . . . . . . . . . . . . . . . . . . . . . 817 About creating components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 817 Working in the Flash environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819 Working with component symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823 Exporting components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828 CHAPTER 40 : Creating Basic Components in Flash MX 2004 . . . . . . . . . . . . 835 Creating simple components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835 Working with component properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842 Binding properties to a custom component. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843 Adding events to custom components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845 Setting default sizes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849 Styling custom components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850 Skinning custom components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851 Creating compound components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853 CHAPTER 41 : Creating Advanced Components in Flash MX 2004 . . . . . . . . . 857 Creating components overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857 Writing the component’s ActionScript code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858 Skinning custom controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881 Adding styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 882 Making components accessible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883 Improving component usability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883 Best practices when designing a component . . . . . . . . . . . . . . . . . . . . . . . . . . . . 884 ModalText.as example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 888 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 891 PART I Presenting Flex This part describes the Macromedia Flex Presentation Server. These chapters introduce Flex, and the two languages that you use to develop Flex applications: MXML and ActionScript. This part also includes an introduction to building Flex applications. The following chapters are included:Chapter 1: Introducing Flex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Chapter 2: Using MXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Chapter 3: Using ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Chapter 4: Developing Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 PART I
Contents Chapter 1: The Microsoft Developer Studio The Microsoft Developer Studio The Project Workspace Project Workspace Window Project Configurations Managing Complex Projects Project Settings Converting Projects Source Code Files Resource Scripts ResourceView Creating New Resources Identifying Resources Dialog Boxes String Tables Accelerator Tables Menus Icons, Bitmaps and Cursors Version Resources Custom Resources The Visual C++ Compiler Compiling on the Command Line The Foundation Classes MFC Source Code Header Files MFC Libraries Summary Chapter 2: The Wizards and The Gallery AppWizard Starting AppWizard Choosing Your Application's User Interface Selecting Database Support Adding Compound Document Support Embellishing Your User Interface Adding Advanced Features Miscellaneous Options Class Names One More Step Other Application Interfaces Choose Carefully! Compiling Your Application Precompiled Header Files ClassWizard Creating a New Class The .clw File The Browser Browser Files Browsing Shortcuts Components and Controls Gallery Summary Chapter 3: The Application Architecture Hierarchy The Application Framework Generating an Application with AppWizard Understanding the Generated Code CDocument and CView CWinApp CWinThread Locating Threads CCmdTarget Commands for Classes About Message Maps How are Message Maps Created? The BEGIN_MESSAGE_MAP() Macro Inside the Message Map Filling the Holes The END_MESSAGE_MAP() Macro Unfolding the Map There's No Sense of Obligation CObject Memory Management Debugging Support Serialization Run-time Type Information Your Own Classes and CObject The Big Picture: A New Life The WinMain() Function MFC's Message Pump Application Termination Summary Chapter 4: The Document/View Architecture Documents and Views Document/View Designs The Different Views Types of Document Document/View Consciousness What are Document Templates? CSingleDocTemplate S
PART 1 PART 2 brief contents FIRST STEPS ................................................................ 1 PART 3 8 ■ STRONG FINISH . ...................................................... 193 1 ■ 2 ■ 3 ■ 4 ■ Getting to know Unity 3 Building a demo that puts you in 3D space 21 Adding enemies and projectiles to the 3D game 46 Developing graphics for your game 69 GETTING COMFORTABLE ........................................... 93 5 ■ 6 ■ 7 ■ Building a Memory game using Unity’s new 2D functionality 95 Putting a 2D GUI in a 3D game 119 Creating a third-person 3D game: player movement and animation 140 Adding interactive devices and items within the game 167 9 ■ 10 ■ 11 ■ 12 ■ Connecting your game to the internet 195 Playing audio: sound effects and music 222 Putting the parts together into a complete game 246 Deploying your game to players’ devices 276 v PART 1 FIRST STEPS . ................................................... 1 foreword xv preface xvii acknowledgments xix about this book xx 1 Getting to know Unity 3 1.1 Why is Unity so great? 4 Unity's strengths and advantages 4 ■ Downsides to be aware of 6 ■ Example games built with Unity 7 1.2 How to use Unity 9 Scene view, Game view, and the Toolbar 10 ■ Using the mouse and keyboard 11 ■ The Hierarchy tab and the Inspector 12 The Project and Console tabs 13 1.3 Getting up and running with Unity programming 14 How code runs in Unity: script components 15 ■ Using MonoDevelop, the cross-platform IDE 16 ■ Printing to the console: Hello World! 17 1.4 Summary 20 vii contents viii CONTENTS 2 Building a demo that puts you in 3D space 21 2.1 Before you start... 22 Planning the project 22 ■ Understanding 3D coordinate space 23 2.2 Begin the project: place objects in the scene 25 The scenery: floor, outer walls, inner walls 25 ■ Lights and cameras 27 ■ The player’s collider and viewpoint 29 2.3 Making things move: a script that applies transforms 30 Diagramming how movement is programmed 30 ■ Writing code to implement the diagram 31 ■ Local vs. global coordinate space 32 2.4 Script component for looking around: MouseLook 33 Horizontal rotation that tracks mouse movement 35 ■ Vertical rotation with limits 35 ■ Horizontal and vertical rotation at the same time 38 2.5 Keyboard input component: first-person controls 40 Responding to key presses 40 ■ Setting a rate of movement independent of the computer’s speed 41 ■ CharacterController for collision detection components for walking instead of flying 2.6 Summary 45 Moving the 42 ■ Adjusting 43 3 Adding enemies and projectiles to the 3D game 46 3.1 Shooting via raycasts 47 What is raycasting? 47 ■ Using the command ScreenPointToRay for shooting for aiming and hits 50 3.2 Scripting reactive targets 53 Determining what was hit 53 ■ it was hit 54 3.3 Basic wandering AI 55 48 ■ Adding visual indicators Alert the target that 56 ■ “Seeing” obstacles What is a prefab? 60 ■ Creating the enemy prefab 60 Instantiating from an invisible SceneController 61 3.5 Shooting via instantiating objects 63 Creating the projectile prefab 64 ■ Shooting the projectile and colliding with a target 65 ■ Damaging the player 67 3.6 Summary 68 Diagramming how basic AI works with a raycast 56 ■ Tracking the character’s state 58 3.4 Spawning enemy prefabs 60 PART 2 Whiteboxing explained 72 ■ Drawing a floor plan for the level 73 ■ Laying out primitives according to the plan 74 4.3 Texture the scene with 2D images 75 Choosing a file format 76 ■ Importing an image file 77 Applying the image 78 4.4 Generating sky visuals using texture images 80 What is a skybox? 80 ■ Creating a new skybox material 81 4.5 Working with custom 3D models 83 Which file format to choose? 83 ■ Exporting and importing the model 84 4.6 Creating effects using particle systems 86 Adjusting parameters on the default effect 87 ■ Applying a new texture for fire 88 ■ Attaching particle effects to 3D objects 90 4.7 Summary 91 GETTING COMFORTABLE ................................ 93 4 Developing graphics for your game 69 4.1 Understanding art assets 69 4.2 Building basic 3D scenery: whiteboxing 72 CONTENTS ix 5 Building a Memory game using Unity’s new 2D functionality 95 5.1 Setting everything up for 2D graphics 96 Preparing the project 97 ■ Displaying 2D images (aka sprites) 98 ■ Switching the camera to 2D mode 101 5.2 Building a card object and making it react to clicks 102 Building the object out of sprites 102 ■ Mouse input code 103 Revealing the card on click 104 5.3 Displaying the various card images 104 Loading images programmatically 104 ■ Setting the image from an invisible SceneController 105 ■ Instantiating a grid of cards 107 ■ Shuffling the cards 109 5.4 Making and scoring matches 110 Storing and comparing revealed cards 111 ■ Hiding mismatched cards 111 ■ Text display for the score 112 x CONTENTS 5.5 Restart button 114 Programming a UIButton component using SendMessage 115 Calling LoadLevel from SceneController 117 5.6 Summary 118 6 Puttinga2DGUIina3Dgame 119 6.1 Before you start writing code... 121 Immediate mode GUI or advanced 2D interface? 121 Planning the layout 122 ■ Importing UI images 122 6.2 Setting up the GUI display 123 Creating a canvas for the interface 123 ■ Buttons, images, and text labels 124 ■ Controlling the position of UI elements 127 6.3 Programming interactivity in the UI 128 Programming an invisible UIController 129 ■ Creating a pop-up window 131 ■ Setting values using sliders and input fields 133 6.4 Updating the game by responding to events 135 Integrating an event system 136 ■ Broadcasting and listening for events from the scene 137 ■ Broadcasting and listening for events from the HUD 138 6.5 Summary 139 7 Creating a third-person 3D game: player movement and animation 140 7.1 Adjusting the camera view for third-person 142 Importing a character to look at 142 ■ Adding shadows to the scene 144 ■ Orbiting the camera around the player character 145 7.2 Programming camera-relative movement controls 148 Rotating the character to face movement direction 149 Moving forward in that direction 151 7.3 Implementing the jump action 152 Applying vertical speed and acceleration 153 ■ Modifying the ground detection to handle edges and slopes 154 7.4 Setting up animations on the player character 158 Defining animation clips in the imported model 160 Creating the animator controller for these animations 162 Writing code that operates the animator 165 7.5 Summary 166 PART 3 8.4 Inventory UI for using and equipping items 186 Displaying inventory items in the UI 186 ■ Equipping a key to use on locked doors 188 ■ Restoring the player’s health by consuming health packs 190 8.5 Summary 191 STRONG FINISH ........................................... 193 CONTENTS xi 8 Adding interactive devices and items within the game 8.1 Creating doors and other devices 168 167 Doors that open and close on a keypress 168 ■ Checking distance and facing before opening the door 170 Operating a color-changing monitor 171 8.2 Interacting with objects by bumping into them 172 Colliding with physics-enabled obstacles 173 ■ Triggering the door with a pressure plate 174 ■ Collecting items scattered around the level 176 8.3 Managing inventory data and game state 178 Setting up player and inventory managers Programming the game managers 180 ■ in a collection object: List vs. Dictionary 178 Storing inventory 184 9 Connecting your game to the internet 195 9.1 Creating an outdoor scene 197 Generating sky visuals using a skybox 197 ■ Setting up an atmosphere that’s controlled by code 198 9.2 Downloading weather data from an internet service 201 Requesting WWW data using coroutines 203 ■ Parsing XML 207 ■ Parsing JSON 209 ■ Affecting the scene based on Weather Data 210 9.3 Adding a networked billboard 212 Loading images from the internet 212 ■ Displaying images on the billboard 214 ■ Caching the downloaded image for reuse 216 9.4 Posting data to a web server 217 Tracking current weather: sending post requests 218 ■ Server- side code in PHP 220 9.5 Summary 221 xii CONTENTS 10 Playing audio: sound effects and music 222 10.1 Importing sound effects 223 Supported file formats 223 ■ Importing audio files 225 10.2 Playing sound effects 226 Explaining what’s involved: audio clip vs. source vs. listener 226 ■ Assigning a looping sound Triggering sound effects from code 229 10.3 Audio control interface 230 Setting up the central AudioManager 230 ■ UI 232 ■ Playing UI sounds 236 10.4 Background music 236 228 Volume control Playing music loops 237 ■ Controlling music volume separately 240 ■ Fading between songs 242 10.5 Summary 245 11 Putting the parts together into a complete game 246 11.1 Building an action RPG by repurposing projects 247 Assembling assets and code from multiple projects 248 Programming point-and-click controls: movement and devices 250 ■ Replacing the old GUI with a new interface 255 11.2 Developing the overarching game structure 261 Controlling mission flow and multiple levels 262 ■ Completing a level by reaching the exit 265 ■ Losing the level when caught by enemies 268 11.3 Handling the player’s progression through the game 269 Saving and loading the player’s progress 269 ■ Beating the game by completing three levels 273 11.4 Summary 275 12 Deploying your game to players’ devices 276 12.1 Start by building for the desktop: Windows, Mac, and Linux 278 Building the application 279 ■ setting the game’s name and icon compilation 281 12.2 Building for the web 282 Unity Player vs. HTML5/WebGL file and a test web page 282 ■ Communicating with JavaScript in the browser 283 Adjusting Player Settings: 280 ■ Platform-dependent 282 ■ Building the Unity CONTENTS xiii 12.3 Building for mobile apps: iOS and Android 285 Setting up the build tools 286 ■ Texture compression 289 Developing plug-ins 290 12.4 Summary 298 afterword 299 appendix A appendix B appendix C appendix D Scene navigation and keyboard shortcuts 302 External tools used alongside Unity 304 Modeling a bench in Blender 308 Online learning resources 316 index 319

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值