码迷,mamicode.com
首页 > 其他好文 > 详细

随机换装

时间:2020-05-02 19:12:37      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:cti   bsp   void   long   imp   不同   reset   esc   舞台   

 

最早写随机换装的功能当初制作邪·白龙的时候、参考原版的代码改了改。但是每一帧的函数修改、显得十分粗苯。

技术图片
  1 package qiangBaiLong
  2 {
  3 
  4     import flash.display.MovieClip;
  5 
  6     import export.monster.Monster1112;
  7 
  8     public class fashion_wq1 extends MovieClip
  9     {
 10 
 11 
 12         public function fashion_wq1()
 13         {
 14             super();
 15             this.to = export.monster.Monster1112.cloth;
 16             addFrameScript(0, this.frame1, 1, this.frame2, 2, this.frame3, 3, this.frame4, 4, this.frame5, 5, this.frame6, 6, this.frame7, 7, this.frame8, 8, this.frame9, 9, this.frame10,10, this.frame11, 11, this.frame12, 12, this.frame13, 13, this.frame14, 14, this.frame15, 15, this.frame16, 16, this.frame17, 17, this.frame18, 18, this.frame19, 19, this.frame20, 20, this.frame21, 21, this.frame22, 22, this.frame23, 23, this.frame24, 24, this.frame25, 25, this.frame26, 26, this.frame27, 27, this.frame28, 28, this.frame29, 29, this.frame30);
 17             return;
 18         }
 19 
 20         function frame1():*
 21         {
 22             this.to = export.monster.Monster1112.cloth;
 23             this.gotoAndPlay(export.monster.Monster1112.cloth);
 24             return;
 25         }
 26         function frame2():*
 27         {
 28             this.to = this;
 29             while (this.to.parent)
 30             {
 31                 this.gotoAndPlay(this.to);
 32                 break;
 33                 this.to = this.to.parent;
 34             }
 35             return;
 36         }
 37         function frame3():*
 38         {
 39             this.to = this;
 40             while (this.to.parent)
 41             {
 42                 this.gotoAndPlay(this.to);
 43                 break;
 44                 this.to = this.to.parent;
 45             }
 46             return;
 47         }
 48         function frame4():*
 49         {
 50             this.to = this;
 51             while (this.to.parent)
 52             {
 53                 this.gotoAndPlay(this.to);
 54                 break;
 55                 this.to = this.to.parent;
 56             }
 57             return;
 58         }
 59         function frame5():*
 60         {
 61             this.to = this;
 62             while (this.to.parent)
 63             {
 64                 this.gotoAndPlay(this.to);
 65                 break;
 66                 this.to = this.to.parent;
 67             }
 68             return;
 69         }
 70         function frame6():*
 71         {
 72             this.to = this;
 73             while (this.to.parent)
 74             {
 75                 this.gotoAndPlay(this.to);
 76                 break;
 77                 this.to = this.to.parent;
 78             }
 79             return;
 80         }
 81         function frame7():*
 82         {
 83             this.to = this;
 84             while (this.to.parent)
 85             {
 86                 this.gotoAndPlay(this.to);
 87                 break;
 88                 this.to = this.to.parent;
 89             }
 90             return;
 91         }
 92         function frame8():*
 93         {
 94             this.to = this;
 95             while (this.to.parent)
 96             {
 97                 this.gotoAndPlay(this.to);
 98                 break;
 99                 this.to = this.to.parent;
100             }
101             return;
102         }
103         function frame9():*
104         {
105             this.to = this;
106             while (this.to.parent)
107             {
108                 this.gotoAndPlay(this.to);
109                 break;
110                 this.to = this.to.parent;
111             }
112             return;
113         }
114         function frame10():*
115         {
116             this.to = this;
117             while (this.to.parent)
118             {
119                 this.gotoAndPlay(this.to);
120                 break;
121                 this.to = this.to.parent;
122             }
123             return;
124         }
125         function frame11():*
126         {
127             this.to = this;
128             while (this.to.parent)
129             {
130                 this.gotoAndPlay(this.to);
131                 break;
132                 this.to = this.to.parent;
133             }
134             return;
135         }
136         function frame12():*
137         {
138             this.to = this;
139             while (this.to.parent)
140             {
141                 this.gotoAndPlay(this.to);
142                 break;
143                 this.to = this.to.parent;
144             }
145             return;
146         }
147         function frame13():*
148         {
149             this.to = this;
150             while (this.to.parent)
151             {
152                 this.gotoAndPlay(this.to);
153                 break;
154                 this.to = this.to.parent;
155             }
156             return;
157         }
158         function frame14():*
159         {
160             this.to = this;
161             while (this.to.parent)
162             {
163                 this.gotoAndPlay(this.to);
164                 break;
165                 this.to = this.to.parent;
166             }
167             return;
168         }
169         function frame15():*
170         {
171             this.to = this;
172             while (this.to.parent)
173             {
174                 this.gotoAndPlay(this.to);
175                 break;
176                 this.to = this.to.parent;
177             }
178             return;
179         }
180         function frame16():*
181         {
182             this.to = this;
183             while (this.to.parent)
184             {
185                 this.gotoAndPlay(this.to);
186                 break;
187                 this.to = this.to.parent;
188             }
189             return;
190         }
191         function frame17():*
192         {
193             this.to = this;
194             while (this.to.parent)
195             {
196                 this.gotoAndPlay(this.to);
197                 break;
198                 this.to = this.to.parent;
199             }
200             return;
201         }
202         function frame18():*
203         {
204             this.to = this;
205             while (this.to.parent)
206             {
207                 this.gotoAndPlay(this.to);
208                 break;
209                 this.to = this.to.parent;
210             }
211             return;
212         }
213         function frame19():*
214         {
215             this.to = this;
216             while (this.to.parent)
217             {
218                 this.gotoAndPlay(this.to);
219                 break;
220                 this.to = this.to.parent;
221             }
222             return;
223         }
224         function frame20():*
225         {
226             this.to = this;
227             while (this.to.parent)
228             {
229                 this.gotoAndPlay(this.to);
230                 break;
231                 this.to = this.to.parent;
232             }
233             return;
234         }
235         function frame21():*
236         {
237             this.to = this;
238             while (this.to.parent)
239             {
240                 this.gotoAndPlay(this.to);
241                 break;
242                 this.to = this.to.parent;
243             }
244             return;
245         }
246         function frame22():*
247         {
248             this.to = this;
249             while (this.to.parent)
250             {
251                 this.gotoAndPlay(this.to);
252                 break;
253                 this.to = this.to.parent;
254             }
255             return;
256         }
257         function frame23():*
258         {
259             this.to = this;
260             while (this.to.parent)
261             {
262                 this.gotoAndPlay(this.to);
263                 break;
264                 this.to = this.to.parent;
265             }
266             return;
267         }
268         function frame24():*
269         {
270             this.to = this;
271             while (this.to.parent)
272             {
273                 this.gotoAndPlay(this.to);
274                 break;
275                 this.to = this.to.parent;
276             }
277             return;
278         }
279         function frame25():*
280         {
281             this.to = this;
282             while (this.to.parent)
283             {
284                 this.gotoAndPlay(this.to);
285                 break;
286                 this.to = this.to.parent;
287             }
288             return;
289         }
290         function frame26():*
291         {
292             this.to = this;
293             while (this.to.parent)
294             {
295                 this.gotoAndPlay(this.to);
296                 break;
297                 this.to = this.to.parent;
298             }
299             return;
300         }
301         function frame27():*
302         {
303             this.to = this;
304             while (this.to.parent)
305             {
306                 this.gotoAndPlay(this.to);
307                 break;
308                 this.to = this.to.parent;
309             }
310             return;
311         }
312         function frame28():*
313         {
314             this.to = this;
315             while (this.to.parent)
316             {
317                 this.gotoAndPlay(this.to);
318                 break;
319                 this.to = this.to.parent;
320             }
321             return;
322         }
323         function frame29():*
324         {
325             this.to = this;
326             while (this.to.parent)
327             {
328                 this.gotoAndPlay(this.to);
329                 break;
330                 this.to = this.to.parent;
331             }
332             return;
333         }
334         function frame30():*
335         {
336             this.to = this;
337             while (this.to.parent)
338             {
339                 this.gotoAndPlay(this.to);
340                 break;
341                 this.to = this.to.parent;
342             }
343             return;
344         }
345         public var to:*;
346     }
347 
348 }
View Code

 

于是这次打算改用其他方式实现随机装备。

 

gotoAndPlay与gotoAndStop的不同之处在于后者跳转之后停止播放。然而无法设置停止时长。

期间犯了低级错误、把静态变量的定义放在类外面了、浪费很久时间才发现。

 

还有一个极大的错误是、为了实现定时换装功能、我将死循环放在构造函数内、以至于无法加载角色入舞台。然后将死循环放在frame1函数内、依旧无法解决问题、原理与放在构造函数内相似、不执行完函数是不会进入下一帧的。

改变思路、以线程代替死循环。然而AS中创建线程不如其他几个语言那样轻松、首先要给予一个适宜的事件、这里我想到的是Timer。使用重复机制代替了死循环。

然后又犯了个错误、虽然是在myTimer中添加事件、但事件处理时this依旧指的是wkywq。

最终:

技术图片
 1 package  {
 2     
 3     import flash.display.MovieClip;
 4     
 5     import flash.events.*;
 6     import flash.utils.Timer;
 7     
 8     
 9     public class wkywq extends MovieClip {
10         
11         
12         public function wkywq() {
13             super();
14             
15             myTimer = Timer(9000, 999) // 间隔为9000 初始重复次数为999
16             myTimer.addEventListener(TimerEvent.TIMER, changeClothes); // 添加事件
17             myTimer.start(); // 启动
18         }
19         
20         public function changeClothes(event:TimerEvent):void {
21             wearClothes = Math.random() * 30; // 不算白装一共30件
22             this.gotoAndStop(wearClothes); // 跳转到
23             myTimer.reset(); // 重置调用
24         }
25 
26         public var myTimer:Timer;
27         
28         public static var wearClothes:int = 0;
29     }    
30 }
View Code

 

你以为这样就结束了?

 

随机换装

标签:cti   bsp   void   long   imp   不同   reset   esc   舞台   

原文地址:https://www.cnblogs.com/kamishiroshinchi/p/12818974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!