-
Notifications
You must be signed in to change notification settings - Fork 0
/
saE.as
2823 lines (2430 loc) · 66.5 KB
/
saE.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package
{
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.text.*;
import flash.events.TimerEvent;
import flash.utils.Timer;
import com.greensock.*;
import com.greensock.plugins.*;
//
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
//
import flash.display.Loader;
import flash.display.Sprite;
///////////
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
////////////
import flash.system.Capabilities;
import flash.desktop.NativeApplication;
import flash.ui.Keyboard;
public class saE extends Sprite
{
var needupdate:int = 0;
///////////txt
var req:URLRequest ;
var loader:URLLoader = new URLLoader ;
////////////////////////
var arrScript:Array;//储存script脚本
var inscript = false;
var ScrI:int=0;
var arrScrInd:int=-1;//脚本片段索引
///////////////////////
var arr:Array;
var ti = 0;//脚本序号
//return
var lastti = 0;//call跳转前的序号
var calllabel = "";//跳转标签
var lastScenario = "";//跳转前脚本
//
var asking = false;
var gotoArr:Array = new Array;//跳转
var loadtxt = false;//是否正在读取
var readScenario:String;//当前使用脚本
var firstScenario:String;//默认初始脚本
/////////////////txt
///////////////cg
var cgXML = new XML ;
var cgfileStream:FileStream;
var cgLoader:URLLoader;// 加载cg图片
var cgArray:Array;//loader数组
var cgPage = 0;//翻页
//////////////cg
var svfileStream:FileStream;//固定变量xml
var savefileStream:FileStream;//存档
var loadXML:XML = new XML ;//读取存档
var StrAutosave:String ="autosave.xml" ;
var StrSave:String ="save.xml" ;//默认保存路径
/////读取配置xml
var initXML = new XML ;
var initLoader:URLLoader;//r = new URLLoader(initURL);
var gameStart = false;
var evallist:XMLList;//变量
var playingat:XMLList;//进度,当前脚本和行号
var sevallist:XMLList;//变量
var tempevallist:XMLList;//临时变量
var craArray:Array = new Array ;//立绘
var askbtnArray:Array = new Array ;//选项
var askArray:Array = new Array ;//选项
var askLoadArray:Array = new Array ;//选项
var bgurl:String = new String ;
var bgdurtime=0;
var durtime = 0;
var sysLoader:Loader = new Loader ;//菜单背景
var btnSLoader:Loader = new Loader ;//存档按钮
var btnLLoader:Loader = new Loader ;//快速读档
var btnBLoader:Loader = new Loader ;//imgreserve1回菜单
var btnRLoader:Loader = new Loader ;//imgreserve2
var btnPLoader:Loader = new Loader ;//回放按钮
var btnSkipLoader:Loader = new Loader ;//自动播放
var saveable=true;
var bgmurl:String;//背景音乐地址
var soundBGM:Sound;
var bgmchannel:SoundChannel;
var BGtransform:SoundTransform;// bgmchannel.soundTransform;
var bgm:URLRequest;
var snd:Sound;//音效
var sndchannel:SoundChannel;
///var iii = new initS ;
public var btnsoundurl="";//按钮音效clicksound
var btnsnd:Sound;
var btnsndchannel:SoundChannel;
var waiting = false;//等待
var waittimer:Timer=new Timer(5000,1);;
var onskip = false;//自动播放
var skiptimer = new Timer(1000,1);
var askmsg = "";//确认对话框参数
var btnwaiting = false;//按钮按下后等待
var waittimerBtn = new Timer(400,1);
var loaderContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);//在ios中加载swf资源
var FileP:File;//存档文件系统位置
var Tformat:TextFormat = new TextFormat();
var SaeText:SaEText;//=new SaEText ;
var SaeBg:SaEBg=new SaEBg ;
var SaeDialog:SaEDialog;
var SaeTrace:SaETrace=new SaETrace;
var SaePlayback:SaEPlayback;//=new SaEPlayback;
var SaeDebug:SaEPlayback;//=new Debug;
var gamedebug=false;
var SaeMsgbox:SaEMsgbox;
var SaeCg:SaECg;
var SaeSavepanel:SaESavepanel;//''''
public function saE()
{
bgurl = "";
bgmurl = "";
trace("☆saE开始01");
// trace(analysisIF.analysis("3>2"));
//trace("ZZZZZZZZZZZZZZZZ"+trimspace(" asd wer "));
//trace("ZZZZZZZZZZZZZZZZ" + trimspace("asd wer "));
//trace("ZZZZZrrrrrrZZZZZ" + replacespace(" a s d w e r "));
trace("zzz"+(true||false&&true));
trace("zzz"+(true&&false||true));
loaderContext.allowCodeImport=true;//允许加载swf中脚本
tracetxt.addChild(SaeTrace);
addEventListener("NEXT",goNext);
addEventListener("LoadError",IMGloadError);
addEventListener("clickBack",msgBack);
addEventListener("clickReplay",msgBack);
addEventListener("clickLoad",msgBack);
addEventListener("keyback",msgBack);
trace("sae01-");
//tracetxt.visible = false;
//if (Capabilities.cpuArchitecture == "ARM")
//if (Capabilities.os.toLowerCase().match("iphone")!=null ||Capabilities.os.toLowerCase().match("mac")!=null)
//trace(Capabilities.os.toLowerCase().substring(0,5));
if (Capabilities.os.toLowerCase().substring(0,6)=="iphone" ||Capabilities.os.toLowerCase().substring(0,3)=="mac")
{
showtrace("mac or ios "+Capabilities.os+"//"+Capabilities.cpuArchitecture);
FileP = new File(File.applicationDirectory.nativePath);
FileP = FileP.resolvePath("..");
}
else if (Capabilities.os.toLowerCase().match("windows")!=null)
{
showtrace("win "+Capabilities.os+"//"+Capabilities.cpuArchitecture);
FileP = new File(File.applicationDirectory.nativePath);
}
else
{
showtrace("android or else,use back to escape "+Capabilities.os+"//"+Capabilities.cpuArchitecture);
FileP = new File(File.applicationStorageDirectory.nativePath);
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN,handleDeactivate,false, 0, true);
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE,onDeactivate); //stage.addEventListener(Event.DEACTIVATE 也可以
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE,onActivate);
}
waittimerBtn.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerBtnComplete);
MCwaiting.alpha = 0;//();
////自动播放timer
mcskip.visible=false;
skiptimer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerSkipComplete);
trace("1//////////");
trace("3//////////");
btnSystem.addChildAt(sysLoader,0);
btnSystem.btnSave.addChildAt(btnSLoader,0);
btnSystem.btnLoad.addChildAt(btnLLoader,0);
btnSystem.btnBack.addChildAt(btnBLoader,0);
btnSystem.btnReplay.addChildAt(btnRLoader,0);
btnSystem.btnPlayback.addChildAt(btnPLoader,0);
btnSystem.btnSkip.addChildAt(btnSkipLoader,0);
//////////////////////
btnsound.addEventListener(MouseEvent.CLICK, clickBtnSound);
//加载字体
var TFloader:Loader = new Loader();
var TFurl:URLRequest = new URLRequest("setting/font.swf");//"fontfish.swf"
TFloader.contentLoaderInfo.addEventListener(Event.COMPLETE, TextformatComplete);
TFloader.load(TFurl,loaderContext);
}
//////////////////////
/////public function xzzz(delimiter: String, ...limit)
//////////////////////
//字体swf加载完成
function TextformatComplete(event:Event):void
{
var fontArray:Array = Font.enumerateFonts(false);
trace("☆字体swf加载完成02fontArray"+fontArray);
Tformat.font = fontArray[0].fontName;
//加载init
var initURL:URLRequest = new URLRequest("setting/init.xml");
initLoader = new URLLoader(initURL);
initLoader.addEventListener(Event.COMPLETE,initxmlLoaded);
//loaderContext.applicationDomain =null;
//loaderContext.allowCodeImport=false;
}
//关闭/打开背景音乐,保留音效
function clickBtnSound(event:MouseEvent):void
{
btnsound.alpha=1;
if(bgmchannel==null)
{
return;
}
//TweenLite.to(btnsound,durtime*4,{delay:2,alpha:0.1});
if(BGtransform == null)
{
bgmvolume(0);
btnsound.gotoAndStop(2);
return;
}
if(BGtransform.volume>0.5)
{
bgmvolume(0);
btnsound.gotoAndStop(2);
}
else
{
bgmvolume(1);
btnsound.gotoAndStop(1);
}
}
//按返回键退出,home键暂停音乐
function handleDeactivate(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.BACK)
{
//提示退出
event.preventDefault();//屏蔽默认事件
showtrace("KEY BACK ");
askmsg = "keyback";
SaeMsgbox.showmsg (askmsg, "要退出了么?");
//NativeApplication.nativeApplication.exit();
}
else if(event.keyCode== Keyboard.MENU)
{
//menu 键
// showtrace("MENU");
}
else if(event.keyCode == Keyboard.SEARCH)
{
// showtrace("SERACHHHH ");
//search
}
else if (event.keyCode == Keyboard.HOME) {
//Handle Home button.
}
}
var BGMposition:Number=0;
function onDeactivate(event:Event):void
{
showtrace("onDeactivateeeeeeee ");
BGMposition=bgmchannel.position;
bgmchannel.stop();
//trace("stop-BGMPOSITION"+BGMposition);
}
function onActivate(event:Event):void
{
showtrace("onActivateeeeeeee ");
bgmchannel = soundBGM.play(BGMposition);
}
//初次写入存档
function updatecgxml():void
{
var UpdcgURL:URLRequest = new URLRequest("setting/cg.xml");
var Updcgloader:URLLoader = new URLLoader(UpdcgURL);
Updcgloader.addEventListener(Event.COMPLETE,UpdcgxmlLoaded);
}
function UpdcgxmlLoaded(event:Event):void
{
trace ("UPDATE CG!!!!");
var UpdcgXML = XML(event.target.data) ;
var xi=cgXML.cgpanel.children().length();
if(UpdcgXML.cgpanel.children().length()>xi)
{
while (UpdcgXML.cgpanel.children().length() > cgXML.cgpanel.children().length())
{
var cx=UpdcgXML.cgpanel.children()[xi];
cgXML.cgpanel.appendChild(cx);
xi++;
}
var file = FileP.resolvePath("Documents/cg.xml");
var stream:FileStream = new FileStream ;
stream.open(file,FileMode.WRITE);
stream.addEventListener(Event.COMPLETE,savecompleteHandler);
stream.writeUTFBytes(cgXML.toString());
stream.close();
trace("CG UpDATE xmlsave");
needupdate ++;
// writeSavexml();
}
}
function updSateStatxml():void
{
var UpdStatURL:URLRequest = new URLRequest("setting/staticvar.xml");
var UpdStatloader:URLLoader = new URLLoader(UpdStatURL);
UpdStatloader.addEventListener(Event.COMPLETE,UpdStatxmlLoaded);
}
function UpdStatxmlLoaded(event:Event):void
{
trace ("UPDATE STATIC!!!!");
//trace (event.target.data);
var UpdStatXML = XML(event.target.data) ;
var xi=sevallist.children().length();
if(UpdStatXML.staticVar.children().length()>xi)
{
while (UpdStatXML.staticVar.children().length() >sevallist.children().length())
{
var cx=UpdStatXML.staticVar.children()[xi];
sevallist.appendChild(cx);
//trace(xi + "SCSCxx " + sevallist);
xi++;
}
var file = FileP.resolvePath("Documents/staticvar.xml");
var stream:FileStream = new FileStream ;
stream.open(file,FileMode.WRITE);
stream.addEventListener(Event.COMPLETE,savecompleteHandler);
stream.writeUTFBytes("<sv>" + sevallist.toString()+ "</sv>");
stream.close();
trace("static update xmlsave");
needupdate ++;
//writeSavexml();
}
}
function writeInitSavefile(numslot:int)
{
var file = FileP.resolvePath("Documents/cg.xml");
if (file.exists)
{
trace("存在存在");//文件存在
loadcgxml();
updatecgxml();
}
else
{
////////////文件不存在则从包中拷贝
var original0:File = File.applicationDirectory.resolvePath("setting/cg.xml");
trace("save不存在 "+original0.nativePath);
var newFile0 = FileP.resolvePath("Documents/cg.xml");
original0.copyTo(newFile0, true);
loadcgxml();
}
file = FileP.resolvePath("Documents/staticvar.xml");
if (file.exists)
{
trace("存在存在");//文件存在
updSateStatxml();
loadstaticvarxml();
}
else
{
////////////文件不存在则从包中拷贝
//showtrace("不存在不存在"+file.nativePath);
var original1:File = File.applicationDirectory.resolvePath("setting/staticvar.xml");
trace("staticvar不存在 "+original1.nativePath);
var newFile1 = FileP.resolvePath("Documents/staticvar.xml");
original1.copyTo(newFile1, true);
loadstaticvarxml();
}
file = FileP.resolvePath("Documents/save.xml");
if (file.exists)
{
trace("save存在存在");//文件存在
loadsavexml();
}
else
{
////////////文件不存在则生成
//showtrace("不存在不存在"+file.nativePath);
var savexml=new XML;
var slotxml=XML("<slot><name/><exist/><img/><txt/><svar/><playingat><scenario/><lastScenario/><lastreadline/><readline/><bgm/><bg/></playingat></slot>");
slotxml.exist=false;
var xmltemp="";//=slotxml;
trace("SLOTxml"+slotxml);
for (var i = 0; i < numslot; i++)
{
slotxml.name=i;
xmltemp+=slotxml.toString();
}
savexml=XML("<save>" +xmltemp + "</save>");
saveXML=savexml;
trace( "savexmlsavexml"+ savexml.children()[2].toString());
var stream:FileStream = new FileStream ;
stream.open(file,FileMode.WRITE);
stream.writeUTFBytes("");
stream.close();
stream.open(file,FileMode.WRITE);
stream.addEventListener(Event.COMPLETE,savecompleteHandler);
stream.writeUTFBytes(savexml.toString());
stream.close();
trace("init save xmlsave");
}
// writeSavexml();
}
//覆盖存档
function anInitSavefile()
{
var original:File = File.applicationDirectory.resolvePath("setting/cg.xml");
trace("cg覆盖 "+original.nativePath);
var newFile = FileP.resolvePath("Documents/cg.xml");
original.copyTo(newFile, true);
SaeCg.initCG();
loadcgxml();
var original1:File = File.applicationDirectory.resolvePath("setting/staticvar.xml");
trace("st 覆盖 "+original1.nativePath);
var newFile1 = FileP.resolvePath("Documents/staticvar.xml");
original1.copyTo(newFile1, true);
loadstaticvarxml();
ti++;
analysisscript(ti);
}
//读取cgxml
function loadcgxml():void
{
cgXML = new XML ;
cgArray=new Array;
cgPage = 0;
trace(" loadcgxml");
var file = FileP.resolvePath("Documents/cg.xml");
cgfileStream = new FileStream();
cgfileStream.addEventListener(Event.COMPLETE, readCgXMLfile);
cgfileStream.openAsync(file, FileMode.READ);
}
//save file''''
function loadsavexml():void
{
trace(" staticvarxml");
var file = FileP.resolvePath("Documents/save.xml");
savefileStream = new FileStream();
savefileStream.addEventListener(Event.COMPLETE, saveXMLfile);
savefileStream.openAsync(file, FileMode.READ);
loadtxt = false;
}
//save file''''
function saveXMLfile(event:Event):void
{
saveXML = new XML ;
saveXML = XML(savefileStream.readUTFBytes(savefileStream.bytesAvailable));
savefileStream.close();
}
//固定变量
function loadstaticvarxml():void
{
trace(" staticvarxml");
var file = FileP.resolvePath("Documents/staticvar.xml");
//var file = FileP.resolvePath("cg.xml");
svfileStream = new FileStream();
svfileStream.addEventListener(Event.COMPLETE, staticvarXMLfile);
svfileStream.openAsync(file, FileMode.READ);
}
//固定变量
function staticvarXMLfile(event:Event):void
{
trace("svfileStreamsvfileStream" );
trace("svfileStream.readUTFBytes==" +svfileStream.readUTFBytes);
trace("svfileStream.bytesAvailable==="+svfileStream.bytesAvailable );
var svXML = XML(svfileStream.readUTFBytes(svfileStream.bytesAvailable));
svfileStream.close();
sevallist = svXML.staticVar;
ansetdurtime();//uodate speed
//trace("evallist sv=" +sevallist);
}
//cgxml
function readCgXMLfile(event:Event):void
{
cgXML = XML(cgfileStream.readUTFBytes(cgfileStream.bytesAvailable));
cgfileStream.close();
SaeCg.readCGXML(cgXML);
}
//初始化
function initxmlLoaded(event:Event):void
{
trace("☆init加载完成03");
gameStart = true;
initXML = XML(initLoader.data);
firstScenario = initXML.playingat.scenario;
playingat = initXML.playingat;
trace(("playingat.scenario" + playingat.scenario));
readScenario = playingat.scenario;
req = new URLRequest(("scenario/" + readScenario));//加载路径
ti = playingat.readline;
////////////txt
trace("☆init-03 加载txt");
loader.load(req);
loader.addEventListener(Event.COMPLETE,TXTcompleteHandler);
/////////////txt;
////读取script
trace("☆init-03 加载txt script");
var reqSc = new URLRequest("scenario/script.txt");//加载路径
var loaderSc:URLLoader = new URLLoader ;
loaderSc.load(reqSc);
loaderSc.addEventListener(Event.COMPLETE,SccompleteHandler);
loaderSc.addEventListener(IOErrorEvent.IO_ERROR, LoadErrorHandler);
///////初始化淡入淡出时间
durtime = parseInt(initXML.durtime)/1000;
trace(durtime+"......................");
skiptimer.delay =parseInt(initXML.skiptime);//
waittimerBtn.delay =parseInt(initXML.btntime);// /
////初始化立绘图层layer
trace("durtime" + durtime);
var i = 0;
for (i = 0; i < initXML.Layer.children().length(); i++)
{
var saeimg:SaEImg=new SaEImg;
craArray.push(saeimg);
imglayer.addChild(craArray[i]);
}
//////////按钮选项按下音效btn sound;
if(initXML.Sui.clicksound. @ url.length()>0)
{
btnsoundurl=initXML.Sui.clicksound. @ url;
}
//////////初始化人物对话框msg;
if(initXML.Sui.msgtalk. @ sizetxt.length()>0)
{
Tformat.size=parseInt(initXML.Sui.msgtalk. @ sizetxt);
}else{
Tformat.size=36;
trace("msgtalk Tformat size default 36");
}
SaeDialog=new SaEDialog(initXML.Sui.msgtalk. @ img,initXML.Sui.msgtalk. @ colorname, initXML.Sui.msgtalk. @ colordialog,Tformat); //
msgTalk.addChild(SaeDialog);
msgTalk.x = initXML.Sui.msgtalk. @ x;
msgTalk.y = initXML.Sui.msgtalk. @ y;
////初始化text
if(initXML.Sui.txtlayer. @ sizetxt.length()>0)
{
Tformat.size=parseInt(initXML.Sui.txtlayer. @ sizetxt);
}else{
Tformat.size=36;
trace("txtlayer Tformat size default 36");
}
SaeText=new SaEText( initXML.Sui.txtlayer. @colortxt,Tformat) ;
txtlayer.visible = false;
txtlayer.addChild(SaeText);
////初始化showtrace
if(initXML.Sui.txttrace. @ sizetxt.length()>0)
{
Tformat.size=parseInt(initXML.Sui.txttrace. @ sizetxt);
}else{
Tformat.size=22;
trace("txttrace Tformat size default 22");
}
SaeTrace.init(initXML.Sui.txttrace. @ colortxt,initXML.Sui.txttrace. @ colorbg,parseInt(initXML.Sui.txttrace. @ durtime),Tformat);
///初始化背景图
imgBG.addChild(SaeBg);
///初始化回放文字
if(initXML.Sui.imgplayback. @ sizetxt.length()>0)
{
Tformat.size=parseInt(initXML.Sui.imgplayback. @ sizetxt);
}else{
Tformat.size=36;
trace("imgplayback Tformat size default 36");
}
var playbacklength;
if(initXML.Sui.imgplayback. @ lines.length()>0)
{
playbacklength=parseInt(initXML.Sui.imgplayback. @ lines);
}else{
playbacklength=8;
trace("imgplayback playbacklength default 8");
}
SaePlayback=new SaEPlayback(initXML.Sui.imgplayback. @ colortxt,initXML.Sui.imgplayback. @ colorbg,Tformat,playbacklength);
txtplayback.addChild(SaePlayback);
///初始化debug
//durtime = parseInt(initXML.durtime)/1000;
if(initXML.debug==true)
{
gamedebug=true;
Tformat.size=30;
SaeDebug=new SaEPlayback("000000","ffffff",Tformat,10);
stage.addChild(SaeDebug);//txtdebug
SaeDebug.showText ();
SaeDebug.mouseEnabled = false;
SaeDebug.mouseChildren = false;
SaeDebug.scaleX=0.5;
SaeDebug.scaleY=0.5;
}
///初始化对话框
if(initXML.Sui.msgbox. @ sizetxt.length()>0)
{
Tformat.size=parseInt(initXML.Sui.msgbox. @ sizetxt);
}else{
Tformat.size=30;
trace("msgbox Tformat size default 30");
}
SaeMsgbox=new SaEMsgbox( initXML.Sui.msgbox. @ colorbg,initXML.Sui.msgbox. @ colortxt,initXML.Sui.msgbox. @ img,initXML.Sui.msgbox. @ pos, Tformat);
msgbox.addChild(SaeMsgbox);
//初始化CG
if(initXML.Sui.cgScreen. @ sizetxt.length()>0)
{
Tformat.size=parseInt(initXML.Sui.cgScreen. @ sizetxt);
trace("@ sizetxt cgScreen "+Tformat.size);
}else{
Tformat.size=26;
trace("cgScreen Tformat size default-26");
}
SaeCg=new SaECg(initXML.Sui.cgScreen.@img, initXML.Sui.cgScreen.@pos,initXML.Sui.cgScreen.@colortxt, initXML.Sui.cgScreen.@txtbg, initXML.Sui.cgScreen.@colorbg, Tformat);
cgSc.addChild(SaeCg);//cgScreen
//初始化save''''
var numslot=initXML.Sui.savepanel. @ numslot;
SaeSavepanel = new SaESavepanel( initXML.Sui.savepanel. @ colorbg, initXML.Sui.savepanel. @ colortxt,
initXML.Sui.savepanel. @ img,
initXML.Sui.savepanel. @ pos, numslot,Tformat);
// slotup + slotup + txtleft + slotup + txtwidth;
savelayer.addChild(SaeSavepanel);//
for (i = 0; i < numslot; i++)
{
SaeSavepanel.saveloaderArray[i].addEventListener(MouseEvent.CLICK,clicksaveslot);
}
/////////sys菜单
var sysURLReq:URLRequest = new URLRequest(initXML.Sui.imgsystem. @ img);
sysLoader.load(sysURLReq);
btnSystem.y = initXML.Sui.imgsystem. @ y;
btnSystem.x = initXML.Sui.imgsystem. @ x1;//)840;
//保存
sysURLReq = new URLRequest(initXML.Sui.imgsave. @ img);
btnSLoader.load(sysURLReq);
btnSystem.btnSave.x = initXML.Sui.imgsave. @ x;
btnSystem.btnSave.y = initXML.Sui.imgsave. @ y;
//没有包含@file属性则使用默认路径save.xml
if(initXML.Sui.imgsave. @file !=null)
{
StrSave=initXML.Sui.imgsave. @ file;
}
//快速读取自动存档
sysURLReq = new URLRequest(initXML.Sui.imgload. @ img);
btnLLoader.load(sysURLReq);
btnSystem.btnLoad.x = initXML.Sui.imgload. @ x;
btnSystem.btnLoad.y = initXML.Sui.imgload. @ y;
///没有包含@file属性则使用默认路径,包含file属性则修改默认存档路径
if(initXML.Sui.imgload. @file !=null)
{
StrAutosave=initXML.Sui.imgload. @file;
trace("nulll");
}
//返回/自定义按钮,自定义提示文字
sysURLReq = new URLRequest(initXML.Sui.imgreserve1. @ img);
btnBLoader.load(sysURLReq);
btnSystem.btnBack.x = initXML.Sui.imgreserve1. @ x;
btnSystem.btnBack.y = initXML.Sui.imgreserve1. @ y;
//重新开始/自定义按钮,自定义提示文字
sysURLReq = new URLRequest(initXML.Sui.imgreserve2. @ img);
btnRLoader.load(sysURLReq);
btnSystem.btnReplay.x = initXML.Sui.imgreserve2. @ x;
btnSystem.btnReplay.y = initXML.Sui.imgreserve2. @ y;
//回顾
sysURLReq = new URLRequest(initXML.Sui.imgplayback. @ img);
btnPLoader.load(sysURLReq);
btnSystem.btnPlayback.x = initXML.Sui.imgplayback. @ x;
btnSystem.btnPlayback.y = initXML.Sui.imgplayback. @ y;
//自动播放
sysURLReq = new URLRequest(initXML.Sui.imgskip. @ img);
btnSkipLoader.load(sysURLReq);
btnSystem.btnSkip.x = initXML.Sui.imgskip. @ x;
btnSystem.btnSkip.y = initXML.Sui.imgskip. @ y;
btnSystem.btnsys.addEventListener(MouseEvent.CLICK,clickShowsys);
//btnSystem.btnSave.addEventListener(MouseEvent.CLICK,clickSave);
btnSystem.btnSave.addEventListener(MouseEvent.CLICK,clickSaveBtn);//''''
btnSystem.btnLoad.addEventListener(MouseEvent.CLICK,clickLoadBtn);
btnSystem.btnBack.addEventListener(MouseEvent.CLICK,clickBack);
btnSystem.btnReplay.addEventListener(MouseEvent.CLICK,clickReplay);
btnSystem.btnPlayback.addEventListener(MouseEvent.CLICK,clickPlayback);
btnSystem.btnSkip.addEventListener(MouseEvent.CLICK,clickSkip);
//////////变量
evallist = initXML.svar;
//trace("evallist=" +evallist);
//////////写入cg和存档,更新staticvar
trace("☆init-03 加载cg和存档");
writeInitSavefile(numslot);//写入cg和存档
stageInit();///////////
}
var saveXML=new XML;
function clicksaveslot(event:Event)
{//''''
//save
trace("clickslot1");
trace(event.currentTarget.parent);
var i = 0;
i = SaeSavepanel.saveloaderArray.indexOf(event.currentTarget);
//var file;// = FileP.resolvePath("Documents/save.xml");
trace("clickslot2==----" + i);
if (savestate == true)
{
//save
saveSlot(i);
}else {
//load
askmsg = "clickLoad";
SaeMsgbox.showmsg (askmsg, initXML.Sui.imgload. @ txt);
loadindex = i;
}
}
var loadindex:int;
/////////////////txt 读取script完成
function SccompleteHandler(e:Event)
{
trace("☆读取script完成04");
arrScript = [];
var arrscT = e.target.data.split("[iscript ");//("<!");
trace("==SC======="+arrscT.length);
for each (var item in arrscT)
{
item="[iscript "+item;
var scT = item.split("\n");
var i = 0;
for (i = 0; i < scT.length; i++)
{
scT[i] = trimspace(scT[i]);
var str = scT[i];
str = str.substring(0, str.indexOf("]") + 1);
scT[i]=str;
if (scT[i].length <= 2 || scT[i].indexOf("//") == 0)
{
//去除空行和注释
scT.splice(i,1);
i--;
}
}
// trace(i + "SCT=" + scT);
if (scT.length > 1)
{
arrScript.push(scT);
}
}
trace("SC读取完成 "+arrScript[1]);
}
function LoadErrorHandler(e:Event)
{
//showtrace("file load error");
}
///////end txt script
////////////////txt脚本读取完成
function TXTcompleteHandler(e:Event)
{
TweenLite.to(MCwaiting,0.5,{alpha:0});
MCwaiting.stop();
waittimer.reset();
waiting = false;
linebreak.play();//显示提示
linebreak.visible = true;
//停止wait
trace("☆txt脚本读取完成04");
arr = new Array ;
loadtxt = true;//读取完成
arr = e.target.data.split("\n");
trace("=============================");
var i = 0;
for (i = 0; i < arr.length; i++)
{
arr[i] = trimspace(arr[i]);
if (arr[i].length <= 1 || arr[i].indexOf("//") == 0)
{
//去除空行和注释
arr.splice(i,1);
i--;
}
}
//跳转数组
gotoArr = new Array ;
for (i = 0; i < arr.length; i++)
{
arr[i] = arr[i].substring(arr[i].indexOf("["),arr[i].indexOf("]") + 1);
var stag = arr[i].substring(1,arr[i].indexOf(" "));
//建立索引
if (stag == "label")
{
var labelname = arr[i].substring(arr[i].indexOf(" ") + 1,arr[i].indexOf("]"));
var ar = [trimspace(labelname),i];
gotoArr.push(ar);
}
}
if (calllabel != "")
{
trace("read=calllabel" + calllabel);
ti = anGOTO(calllabel, 0);
}
trace("read= ti" + ti);
analysisscript(ti);
txtlayer.addEventListener(MouseEvent.CLICK,clickNext);
msgTalk.addEventListener(MouseEvent.CLICK,clickNext);
btnNext.addEventListener(MouseEvent.CLICK,clickNext);
}
///////txt
/////////////////////Timer等待结束
function onTimerComplete(event:TimerEvent):void
{
//等待
TweenLite.to(MCwaiting,0.5,{alpha:0});
MCwaiting.stop();
waiting = false;
linebreak.play();//显示提示
linebreak.visible = true;
if (!inscript )
{
trace("auto t");
ti++;
analysisscript(ti);
}else {
trace("auto S ScrI="+ScrI+" arrScrInd= "+arrScrInd);
ScrI++;
anIscript(arrScript[arrScrInd],ScrI);
}
trace("Time's Up!");
if(onskip)
{
skiptimer.start();
}
}
function stopTimerSkip():void
{
//停止自动播放
//trace("停止自动播放");
skiptimer.reset();
onskip = false;
mcskip.visible=false;
}
function onTimerSkipComplete(event:TimerEvent):void
{
//自动播放timer
if (! gameStart || ! loadtxt ||waiting)
{
trace("正在等待");
return;
}
if (! asking)
{
linebreak.stop();
linebreak.visible = false;
ti++;
if ((ti >= arr.length))
{
ti = 0;
}
analysisscript(ti);
}
if(onskip)
{
skiptimer.start();
}else{
mcskip.visible=false;
}
}