我來自 AS2,無法轉換為 AS3。我正在嘗試使用影片剪輯制作爆炸粒子,但一直遇到錯誤。
這是原始的 AS2 腳本:
maxparticles = 200; //number of particles
i = 0; //counter, for "while" loop
while(i < maxparticles){
newparticlename = "particle" i; //creates a new name for a new particle instance
particle.duplicateMovieClip(newparticlename, i); //duplicates our particle mc
i ;
}
這是我轉換后的 AS3 腳本:
var maxparticles = 200; //number of particles
var i = 0; //counter, for "while" loop
while(i < maxparticles){
var newparticlename = "particle" i; //creates a new name for a new particle instance
particle.duplicateMovieClip(newparticlename, i); //duplicates our particle mc
i ;
}
我在這里不斷遇到問題:
particle.duplicateMovieClip(newparticlename, i);
任何幫助是極大的贊賞。
uj5u.com熱心網友回復:
AS3做的事情有點不同。沒有像duplicateMovieClip這樣的方法,也沒有這樣的概念。AS3以更加物件化的方式操作視覺物件(MovieClip、Shape等):您可以創建和銷毀它們,可以將它們保存在記憶體中以備后用,您可以將它們與各自的父物件分離并重新將它們附加到其他地方。
為了創建同一物件的多個實體,請執行以下操作:
- 在專案的庫中將其創建為MovieClip(而不是Graphic )項。
- 在庫屬性中為其分配一個類并命名該類,例如Particle。基類應該是MovieClip(它是默認的)。我無法提供任何螢屏,但應該不難弄清楚。
- 放置以下代碼:
(請記住它沒有經過測驗,但這個概念應該是正確的)
// Allows the script to interact with the Particle class.
import Particle;
// Number of particles.
var maxparticles:int = 200;
// I imagine you will need to access the particles somehow
// in order to manipulate them, you'd better put them into
// an Array to do so rather then address them by their names.
var Plist:Array = new Array;
// Counter, for "while" loop.
var i:int = 0;
// The loop.
while (i < maxparticles)
{
// Let's create a new particle.
// That's how it is done in AS3.
var P:Particle = new Particle;
// The unique name for the new particle. Whatever you want it for.
P.name = "particle" i;
// Enlist the newly created particle.
Plist.push(P);
// At the moment, the P exists but is not yet attached to the display list
// (or to anything). It's a new concept, there wasn't such thing in AS2.
// Let's make it a part of the display list so that we can see it.
addChild(P);
i ;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/529270.html
下一篇:我的服裝小部件未顯示在列中
