|
查看: 1922|回复: 6
|
[AS 2.0]關于function用法與問題
[复制链接]
|
|
|
最近初學function的用法,不過遇到了小問題。
首先我在Stage上做了2個Dynamic TextField,Instance Name為:
1.LatestNewsText
2.GalleryText
下面是我的Code:
LatestNewsText1 = "Poverty is the shortage of common things such as food, clothing, shelter and safe drinking water, all of which determine the quality of life. ";
GalleryText1 = "The Gallery Project is an open source project enabling management and publication of digital photographs and other media through a PHP-enabled web server. ";
function TextEffect(TargetTextBox,TargetString,CounterName) {
CounterName = 1;
this.onEnterFrame = function() {
if (CounterName<TargetString.length) {
TargetTextBox.text = TargetString.substr(0, CounterName);
CounterName++;
} else {
TargetTextBox.text = TargetString;
}
};
}
a=TextEffect(LatestNewsText,LatestNewsText1,count1);
b=TextEffect(GalleryText,GalleryText1,count2);
stop();
若大大照著做,再Copy以上的Code在第一個Frame,會看到LatestNewsText無法顯示,可是GalleryText顯示正常。
這是不是因為一個Function只能讓一個Instance用?還是名字和排法上面出了問題?
雖然可以個別讓他們寫同樣的Coding,可是想要學更實際的function用法。有哪一位大大可以教教?
[ 本帖最后由 VernGalaxy 于 31-5-2009 05:45 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 31-5-2009 09:17 AM
|
显示全部楼层
LatestNewsText1 = "Poverty is the shortage of common things such as food, clothing, shelter and safe drinking water, all of which determine the quality of life. ";
GalleryText1 = "The Gallery Project is an open source project enabling management and publication of digital photographs and other media through a PHP-enabled web server. ";
function TextEffect(TargetTextBox, TargetString) {
CounterName = 1;
TargetTextBox.onEnterFrame = function() {
if (CounterName<TargetString.length) {
this.ttt.text = TargetString.substr(0, CounterName);
CounterName++;
} else {
this.ttt.text = TargetString;
}
};
}
TextEffect(LatestNewsText,LatestNewsText1);
TextEffect(GalleryText,GalleryText1);
stop(); |
|
|
|
|
|
|
|
|
|
|
发表于 31-5-2009 09:18 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 31-5-2009 01:11 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 18-8-2009 09:44 PM
|
显示全部楼层
最近在做Project。對于Function遇到了一點小問題。。。
下面是我其中一個Frame的Code:
this.onEnterFrame = function() {
Uterus.onRollOver = CaptionText;
Cervix.onRollOver = CaptionText;
Ovary.onRollOver = CaptionText;
Endometrium.onRollOver = CaptionText;
Fallopian_Tube.onRollOver = CaptionText;
Vagina.onRollOver = CaptionText;
Uterus_Cavity.onRollOver = CaptionText;
if (StructureDescriptionTitle.betaText.text == "undefined") {
_root.StructureDescriptionContent.betaText.htmlText = "__________________________";
_root.StructureDescriptionTitle.betaText.text = "Select a Part";
}
};
CaptionText = function () {
Mouse.hide();
gotoAndPlay(261);
IndicatorSpotName = this._name;
_root.attachMovie("IndicatorText","IndicatorText",9997,{_x:_root._xmouse, _y:_root._ymouse});
_root.IndicatorText.IndicatorTextMaterial1.betaText.text = IndicatorSpotName;
_root.IndicatorText.IndicatorTextMaterial1.betaText.replaceText(_root.IndicatorText.IndicatorTextMaterial1.betaText.text.indexOf("_"),_root.IndicatorText.IndicatorTextMaterial1.betaText.text.indexOf("_")+1," ");
_root.IndicatorText.startDrag();
myLoadVar = new LoadVars();
myLoadVar.load("Structure of female reproductive system.txt");
myLoadVar.onLoad = function(success) {
if (success == true) {
_root.StructureDescriptionContent.betaText.htmlText = this[IndicatorSpotName];
_root.StructureDescriptionTitle.betaText.text = _root.IndicatorText.IndicatorTextMaterial1.betaText.text;
_root.StructureDescriptionContent.betaText.autoSize = true;
}
};
this.onRollOut = function() {
gotoAndPlay(261);
Mouse.show();
_root.StructureDescriptionContent.betaText.htmlText = "__________________________";
_root.StructureDescriptionTitle.betaText.text = "Select Organ Parts";
_root.Indicator.gotoAndPlay(11);
_root.IndicatorText.stopDrag();
_root.IndicatorText.gotoAndStop(11);
};
};
BackToTitle.onRelease = function() {
delete CaptionText
BackTo = "Index";
gotoAndPlay("StructureOfFemaleReproductiveSystemBack");
};
BackToSubTitle.onRelease = function() {
delete CaptionText
_global.CurrentSubTitleSubTitle = 1;
BackTo = "ChosenTitle";
gotoAndPlay("StructureOfFemaleReproductiveSystemBack");
};
對于紅色Highlighted的字串,雖然我delete了CaptionText的Function,基本上Function里面的attachMovie等等都不會再出現。應該說整個function已經會不存在才對。可是偏偏在gotoAndPlay(261);卻如常運行。有誰能夠解釋嗎?
注:StructureOfFemaleReproductiveSystemBack是后面讓這個畫面慢慢消失的效果,所以在這里我找到的bug就是在沒完全消失之前,Mouse rollover,卻又運行了CaptionText(除了gotoAndPlay(261),其他的function所包含內容卻沒有運行)。我試過 delete this.onEnterFrame,this.onEnterFrame=null,還是一樣。。。
有點亂。。。希望大大能看得懂。 |
|
|
|
|
|
|
|
|
|
|
发表于 19-8-2009 03:43 AM
|
显示全部楼层
原帖由 VernGalaxy 于 18-8-2009 09:44 PM 发表 
最近在做Project。對于Function遇到了一點小問題。。。
下面是我其中一個Frame的Code:引用:this.onEnterFrame = function() {
Uterus.onRollOver = CaptionText;
Cervix.onRollOver = CaptionText;
Ovary.onRollOver = CaptionText;
Endometrium.onRollOver = CaptionText;
Fallopian_Tube.onRollOver = CaptionText;
Vagina.onRollOver = CaptionText;
Uterus_Cavity.onRollOver = CaptionText;
if (StructureDescriptionTitle.betaText.text == "undefined") {
_root.StructureDescriptionContent.betaText.htmlText = "__________________________";
_root.StructureDescriptionTitle.betaText.text = "Select a Part";
}
};
CaptionText = function () {
Mouse.hide();
gotoAndPlay(261);
IndicatorSpotName = this._name;
_root.attachMovie("IndicatorText","IndicatorText",9997,{_x:_root._xmouse, _y:_root._ymouse});
_root.IndicatorText.IndicatorTextMaterial1.betaText.text = IndicatorSpotName;
_root.IndicatorText.IndicatorTextMaterial1.betaText.replaceText(_root.IndicatorText.IndicatorTextMaterial1.betaText.text.indexOf("_"),_root.IndicatorText.IndicatorTextMaterial1.betaText.text.indexOf("_")+1,"");
_root.IndicatorText.startDrag();
myLoadVar = new LoadVars();
myLoadVar.load("Structure of female reproductive system.txt");
myLoadVar.onLoad = function(success) {
if (success == true) {
_root.StructureDescriptionContent.betaText.htmlText = this[IndicatorSpotName];
_root.StructureDescriptionTitle.betaText.text =_root.IndicatorText.IndicatorTextMaterial1.betaText.text;
_root.StructureDescriptionContent.betaText.autoSize = true;
}
};
this.onRollOut = function() {
gotoAndPlay(261);
Mouse.show();
_root.StructureDescriptionContent.betaText.htmlText = "__________________________";
_root.StructureDescriptionTitle.betaText.text = "Select Organ Parts";
_root.Indicator.gotoAndPlay(11);
_root.IndicatorText.stopDrag();
_root.IndicatorText.gotoAndStop(11);
};
};
BackToTitle.onRelease = function() {
delete CaptionText
BackTo = "Index";
gotoAndPlay("StructureOfFemaleReproductiveSystemBack");
};
BackToSubTitle.onRelease = function() {
delete CaptionText
_global.CurrentSubTitleSubTitle = 1;
BackTo = "ChosenTitle";
gotoAndPlay("StructureOfFemaleReproductiveSystemBack");
};
對于紅色Highlighted的字串,雖然我delete了CaptionText的Function,基本上Function里面的attachMovie等等都不會再出現。應該說整個function已經會不存在才對。可是偏偏在gotoAndPlay(261);卻如常運行。有誰能夠解釋嗎?
注:StructureOfFemaleReproductiveSystemBack是后面讓這個畫面慢慢消失的效果,所以在這里我找到的bug就是在沒完全消失之前,Mouserollover,卻又運行了CaptionText(除了gotoAndPlay(261),其他的function所包含內容卻沒有運行)。我試過delete this.onEnterFrame,this.onEnterFrame=null,還是一樣。。。
有點亂。。。希望大大能看得懂。
厄.... 你的 coding 不是完整, 所以不太能夠想像運行時候的情況
但基本上 onRollOver 所賦予的 function 會獨立儲存在另一塊 memory 位置上, 所以你刪除原本的 function 其事件會依然執行著
再來不明白為何要把賦予 onRollOver 的 coding 寫在 onEnterFrame 中呢?? 你可以嘗試改成這樣
this.onEnterFrame = function() {
//如果能夠這裡也最好可以不要寫在 onEnterFrame 中
if (StructureDescriptionTitle.betaText.text == "undefined") {
_root.StructureDescriptionContent.betaText.htmlText = "__________________________";
_root.StructureDescriptionTitle.betaText.text = "Select a Part";
}
};
function assignRollOver()
{
Uterus.onRollOver = CaptionText;
Cervix.onRollOver = CaptionText;
Ovary.onRollOver = CaptionText;
Endometrium.onRollOver = CaptionText;
Fallopian_Tube.onRollOver = CaptionText;
Vagina.onRollOver = CaptionText;
Uterus_Cavity.onRollOver = CaptionText;
}
assignRollOver(); //需要的時候呼叫這個函數賦予 onRollOver 事件
function removeRollOver()
{
delete Uterus.onRollOver;
delete Cervix.onRollOver;
delete Ovary.onRollOver;
delete Endometrium.onRollOver;
delete Fallopian_Tube.onRollOver;
delete Vagina.onRollOver;
delete Uterus_Cavity.onRollOver;
}
CaptionText = function () {
Mouse.hide();
gotoAndPlay(261);
IndicatorSpotName = this._name;
_root.attachMovie("IndicatorText","IndicatorText",9997,{_x:_root._xmouse, _y:_root._ymouse});
_root.IndicatorText.IndicatorTextMaterial1.betaText.text = IndicatorSpotName;
_root.IndicatorText.IndicatorTextMaterial1.betaText.replaceText(_root.IndicatorText.IndicatorTextMaterial1.betaText.text.indexOf("_"),_root.IndicatorText.IndicatorTextMaterial1.betaText.text.indexOf("_")+1," ");
_root.IndicatorText.startDrag();
myLoadVar = new LoadVars();
myLoadVar.load("Structure of female reproductive system.txt");
myLoadVar.onLoad = function(success) {
if (success == true) {
_root.StructureDescriptionContent.betaText.htmlText = this[IndicatorSpotName];
_root.StructureDescriptionTitle.betaText.text = _root.IndicatorText.IndicatorTextMaterial1.betaText.text;
_root.StructureDescriptionContent.betaText.autoSize = true;
}
};
this.onRollOut = function() {
gotoAndPlay(261);
Mouse.show();
_root.StructureDescriptionContent.betaText.htmlText = "__________________________";
_root.StructureDescriptionTitle.betaText.text = "Select Organ Parts";
_root.Indicator.gotoAndPlay(11);
_root.IndicatorText.stopDrag();
_root.IndicatorText.gotoAndStop(11);
};
};
BackToTitle.onRelease = function() {
removeRollOver() //不需要的時候把所有指定 onRollOver 事件刪除
BackTo = "Index";
gotoAndPlay("StructureOfFemaleReproductiveSystemBack");
};
BackToSubTitle.onRelease = function() {
removeRollOver()
_global.CurrentSubTitleSubTitle = 1;
BackTo = "ChosenTitle";
gotoAndPlay("StructureOfFemaleReproductiveSystemBack");
}; |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 19-8-2009 05:06 PM
|
显示全部楼层
因為我的資料顯示是讓整個Flash重復跑特定范圍的frames來更換不同的資料,所以需要onEnterFrame。還不知道原來function會個別存在于不同層面上,多謝指點。
嗯嗯 大致上延用了大大的function,只是改了一下下 。現在問題已經解決了,多謝Tomato兄~ |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|