1 4 5 9 10 package org.openlaszlo.compiler; 11 12 import org.openlaszlo.sc.ScriptCompiler; 13 import org.openlaszlo.utils.ChainedException; 14 15 import org.openlaszlo.iv.flash.util.*; 16 import org.openlaszlo.iv.flash.api.*; 17 import org.openlaszlo.iv.flash.api.button.*; 18 import org.openlaszlo.iv.flash.api.action.*; 19 import org.openlaszlo.iv.flash.api.image.*; 20 import org.openlaszlo.iv.flash.api.sound.*; 21 import org.openlaszlo.iv.flash.api.text.*; 22 import org.openlaszlo.iv.flash.api.shape.*; 23 24 import java.awt.geom.Rectangle2D ; 25 import java.awt.geom.AffineTransform ; 26 27 import java.io.*; 28 29 import java.util.Properties ; 30 31 import org.apache.log4j.*; 32 33 39 class SWFFile extends FlashFile { 40 41 public static final int TWIP = 20; 42 public static final int KEYCODE_ENTER = 13; 43 public static final int KEYCODE_TAB = 18; 44 45 private Properties mProperties = null; 46 47 50 protected DoAction actionBlock(String s) { 51 return new DoAction(program(s)); 52 } 53 54 57 protected Program program(String s) { 58 byte[] action = ScriptCompiler.compileToByteArray(s, mProperties); 59 return new Program(action, 0, action.length); 60 } 61 62 63 68 protected void export(String n, FlashDef def) { 69 addDef(def); 70 ExportAssets ea = new ExportAssets(); 71 ea.addAsset(n, def); 72 Frame frame = getMainScript().getFrameAt(0); 73 frame.addFlashObject(ea); 74 } 75 76 79 private Shape rectangle() { 80 Shape shape = new Shape(); 81 shape.setFillStyle1( FillStyle.newSolid( AlphaColor.white ) ); 82 Rectangle2D r = new Rectangle2D.Double (0, 0, 100*TWIP, 100*TWIP); 83 shape.drawRectangle( r ); 84 shape.setBounds( r ); 85 return shape; 86 } 87 88 93 public SWFFile(String path, Properties props) { 94 95 mProperties = props; 96 97 98 try { 99 100 String s; 101 Script movieClip, empty; 102 ClipActions ca; 103 Instance inst; 104 DoAction block; 105 Frame f0, f1; 106 Program p; 107 Button2 but; 108 Shape shape; 109 AffineTransform at = new AffineTransform (); 110 AffineTransform offScreen = new AffineTransform (); 111 int states; 112 113 Script mainScript = new Script(1); 114 mainScript.setMain(); 115 setMainScript(mainScript); 116 Frame frame = getMainScript().getFrameAt(0); 117 Shape rectShape = rectangle(); 118 119 but = new Button2(); 121 states = ButtonRecord.HitTest; 122 but.addButtonRecord(new ButtonRecord(states, rectShape, 1, at, new CXForm())); 123 but.addActionCondition( 125 new ActionCondition(KEYCODE_TAB<<9, program("_root.LzKeys.gotKeyDown(9, 'extra');")) 126 ); 127 offScreen.scale(.1, .1); 128 offScreen.translate(-200*TWIP, -200*TWIP); 129 frame.addInstance(but, 9, offScreen, null); 131 132 movieClip = new Script(2); 134 movieClip.getFrameAt(0).addStopAction(); 136 but = new Button2(); 138 states = ButtonRecord.HitTest; 139 but.addButtonRecord(new ButtonRecord(states, rectShape, 1, at, new CXForm())); 140 but.addActionCondition(new ActionCondition(KEYCODE_ENTER<<9, new Program())); 141 movieClip.getFrameAt(1).addInstance(but, 1, null, null); 142 frame.addInstance(movieClip, 11, offScreen, null, "entercontrol"); 144 145 movieClip = new Script(2); 147 block = actionBlock("_root.LzIdle.onidle.sendEvent( getTimer() );"); 148 movieClip.getFrameAt(0).addFlashObject(block); 149 movieClip.getFrameAt(1).addFlashObject(block); 150 151 inst = frame.addInstance(movieClip, 2, null, null, "frameupdate"); 154 ca = new ClipActions(); 155 ca.setMask(ClipAction.KEY_DOWN|ClipAction.KEY_UP|ClipAction.MOUSE_DOWN|ClipAction.MOUSE_UP); 156 s = "_root.LzKeys.gotKeyDown(Key.getCode())"; 157 ca.addAction(new ClipAction(ClipAction.KEY_DOWN, program(s))); 158 s = "_root.LzKeys.gotKeyUp(Key.getCode())"; 159 ca.addAction(new ClipAction(ClipAction.KEY_UP, program(s))); 160 s = "_root.LzModeManager.rawMouseEvent('onmousedown')"; 161 ca.addAction(new ClipAction(ClipAction.MOUSE_DOWN, program(s))); 162 s = "_root.LzModeManager.rawMouseEvent('onmouseup')"; 163 ca.addAction(new ClipAction(ClipAction.MOUSE_UP, program(s))); 164 inst.actions = ca; 165 166 empty = movieClip = new Script(1); 168 export("empty", movieClip); 169 170 movieClip = new Script(1); 180 export("LzMask", movieClip); 181 f0 = movieClip.getFrameAt(0); 182 183 193 194 f0.addInstance(empty, 4, null, null, "mask_sub"); 196 197 inst = f0.addInstance(rectShape, 3, at, null); 199 inst.clip = 6; 201 202 movieClip = new Script(1); 205 export("LzMouseEvents", movieClip); 206 but = new Button2(); 207 states = ButtonRecord.HitTest; 208 but.addButtonRecord(new ButtonRecord(states, rectShape, 1, at, new CXForm())); 209 but.addActionCondition(ActionCondition.onPress(program( 210 "_root.LzModeManager.handleMouseButton( myView, 'onmousedown')"))); 211 but.addActionCondition(ActionCondition.onRelease(program( 212 "_root.LzModeManager.handleMouseButton( myView, 'onmouseup');" + 213 "_root.LzModeManager.handleMouseEvent( myView, 'onclick')"))); 214 but.addActionCondition(ActionCondition.onReleaseOutside(program( 215 "_root.LzModeManager.handleMouseButton( myView, 'onmouseup');" + 216 "_root.LzModeManager.handleMouseEvent( myView, 'onmouseupoutside')"))); 217 but.addActionCondition(ActionCondition.onRollOver(program( 218 "_root.LzModeManager.handleMouseEvent( myView, 'onmouseover')"))); 219 but.addActionCondition(ActionCondition.onRollOut(program( 220 "_root.LzModeManager.handleMouseEvent( myView, 'onmouseout')"))); 221 but.addActionCondition(ActionCondition.onDragOut(program( 222 "_root.LzModeManager.handleMouseEvent( myView, 'onmouseout');" + 223 "_root.LzModeManager.handleMouseEvent( myView, 'onmousedragout')"))); 224 but.addActionCondition(ActionCondition.onDragOver(program( 225 "_root.LzModeManager.handleMouseEvent( myView, 'onmouseover');" + 226 "_root.LzModeManager.handleMouseEvent( myView, 'onmousedragin')"))); 227 movieClip.getFrameAt(0).addInstance(but, 1, at, null); 228 229 movieClip = new Script(1); 231 export("swatch", movieClip); 232 f0 = movieClip.getFrameAt(0); 233 f0.addInstance(rectShape, 1, at, null); 234 235 String krank = mProperties.getProperty(CompilationEnvironment.KRANK_PROPERTY); 237 if ("true".equals(krank)) { 238 movieClip = new Script(2); 239 export("__LZkranker", movieClip); 240 f0 = movieClip.getFrameAt(0); 241 f0.addFlashObject(actionBlock("_root.LzSerializer.procStack();")); 242 f1 = movieClip.getFrameAt(1); 243 f1.addFlashObject(actionBlock("_root.LzSerializer.procStack()")); 244 } 245 246 String profile = mProperties.getProperty(CompilationEnvironment.PROFILE_PROPERTY); 248 if ("true".equals(profile)) { 249 movieClip = new Script(2); 250 export("__LZprofiler", movieClip); 251 block = actionBlock("_root.$lzprofiler.dump()"); 252 movieClip.getFrameAt(0).addFlashObject(block); 253 movieClip.getFrameAt(1).addFlashObject(block); 254 } 255 256 String debug = mProperties.getProperty(CompilationEnvironment.DEBUG_PROPERTY); 258 if ("true".equals(debug)) { 259 movieClip = new Script(2); 260 export("__LZdebugger", movieClip); 261 block = actionBlock("_root.__LzDebug.background()"); 262 movieClip.getFrameAt(0).addFlashObject(block); 263 movieClip.getFrameAt(1).addFlashObject(block); 264 } 265 266 FlashFile oldLibrary = FlashFile.parse(path); 268 IVVector objs = oldLibrary.getMainScript().getFrameAt(0); 269 block = (DoAction)objs.elementAt(0); 270 if (block == null) { 271 throw new ChainedException("no DoAction block in " + path); 272 } 273 frame.addFlashObject(block); 274 275 block = actionBlock("global[ '$endOfLFCMarker' ];"); 277 frame.addFlashObject(block); 278 279 } catch (IVException e) { 280 throw new ChainedException(e); 281 } catch (FileNotFoundException e) { 282 throw new ChainedException(e); 283 } catch (IOException e) { 284 throw new ChainedException(e); 285 } 286 } 287 288 291 public SWFFile(Properties props) { 292 mProperties = props; 293 } 294 295 298 void addPreloaderFrame(String preloadLibPath) { 299 300 try { 301 Timeline tm = getMainScript().getTimeline(); 303 tm.insertFrames(0, 1); 304 305 Script prelClip = new Script(1); 307 prelClip.setName("lzpreloader"); 308 Frame frame = prelClip.getFrameAt(0); 309 FlashFile lib = FlashFile.parse(preloadLibPath); 311 IVVector objs = lib.getMainScript().getFrameAt(0); 312 DoAction block = (DoAction)objs.elementAt(0); 313 frame.addFlashObject(block); 314 315 export("lzpreloader", prelClip); 317 318 tm.getFrameAt(0).addInstance(prelClip, 1, null, null, "lzpreloader"); 320 321 } catch (IVException e) { 322 throw new ChainedException(e); 323 } catch (FileNotFoundException e) { 324 throw new ChainedException(e); 325 } catch (IOException e) { 326 throw new ChainedException(e); 327 } 328 } 329 } 330 | Popular Tags |