PDA

Volledige versie bekijken : Opmerkelijk(iets met tekstveldbenaming)


renegeuze
%Europe/Berlin %798 %2006, 20:09
Eindelijk een topic waar ik niet echt hulp vraagt(dat mag toch nog wel hé =p)
Ik heb de volgende code in flash 8 AS2

contentArray = ['<b><i>testing head</i></b>', 'testing the array'];
from0 = contentArray[0].length;
from1 = contentArray[1].length;
setInterval(textAnimation, 20);
function textAnimation() {
if (from0>0) {
from0 -= 1;
to0 = contentArray[0].length;
tekst0 = contentArray[0].substring(from0, to0);
}
if (from1>0) {
from1 -= 1;
to1 = contentArray[1].length;
tekst1 = contentArray[1].substring(from1, to1);
}
}

Ik zal het maar verklappen, bovenstaand script werkt prima.
Maar waarom ik dit topic open is het volgende script:

contentArray = ['<b><i>testing head</i></b>', 'testing the array'];
from0 = contentArray[0].length;
from1 = contentArray[1].length;
setInterval(textAnimation, 20);
function textAnimation() {
if (from0>0) {
from0 -= 1;
to0 = contentArray[0].length;
text0 = contentArray[0].substring(from0, to0);
}
if (from1>0) {
from1 -= 1;
to1 = contentArray[1].length;
text1 = contentArray[1].substring(from1, to1);
}
}

Het enige verschil is dat ik tekst0 en tekst1 heb vervangen met text0 en text1. Het vreemde is dat in dit geval text0 wel werkt en text1 niet. Als ik de nummers omwissel maakt dat ook niets uit.
Ik zie niet echt het verschil tussen tekst0 gebruiken of text0 gebruiken...
Weet iemand of hier ook maar enigzins een zinnige verklaring voor is te geven? zo ja, welke?

edit: owja, hij laat wel in beide gevallen de contentArray[1] zien in het veld...

Dauntless
%Europe/Berlin %806 %2006, 20:20
Kan je even bijgaande .fla online zetten ?

renegeuze
%Europe/Berlin %813 %2006, 20:31
Zip in originele post gezet.
Het is een oud foto album wat ik ooit heb gedownload dat ik opnieuw aan het schrijven ben. Ben pas gister in de bus begonnen dus aan style komt het je misschien zelfs wel bekend voor aangezien ik daar nog weinig aan heb gedaan.

Dauntless
%Europe/Berlin %820 %2006, 20:41
Hehe, geen flash bug...

Vul NOOIT maar dan ook NOOIT hetzelfde in bij 'var' als bij 'instancenaam'. Dan bestaan er immers 2 dingen met dezelfde naam (een textfield en een variabele) en dat kan niet.

Het is ook beter om altijd via de instancenaam te werken. Vergeet dat die 'var' bestaat :). (En gebruik .text om de inhoud van een tekstvak aan te spreken).


//EDIT
Ik zag juist je vraagi n het andere topic: "waarom is var slecht en instancenaam goed?"

Wel, als je ook maar IETS wil doen met een textvak (via AS), buiten er iets inzetten, heb je een instance naam nodig. Denk aan textformat instellen, _x, _y, _widht, _height, _visible, border, borderColor, etc .

Waarom zou je dan 2 dingen naast elkaar gebruiken? Je begint bv met overal 'var' te gebruiken. Dan merk je plots dat je wil dat er iets met het textfield gebeurt... Je zoekt op hoe dat gaat en je ziet dat het via de instancenaam moet. Dan ga je bij instancenaam iets moeten invullen en de kans is groot dat je dan dus hetzelfde gaat invullen als de varnaam. Dat zorgt dus al voor bugs (en je weet waarschijnlijk nog niet eens hoe dat komt, zoals hier).

Dus: Waarom een extra var aanmaken voor de inhoud te controleren, wanneer je dat ook via de instancenaam kan doen, die je toch uiteindelijk wel zult gebruiken ?

Duidelijk? :D

renegeuze
%Europe/Berlin %828 %2006, 20:52
Uh sorry dat snap ik. Dat is er perongeluk ingeslopen terwijl ik dus aan het kloten was met waarom die het niet deed. En als je het zou uitproberen zou je doorhebben dat het daar niet eens aan ligt.(de instance name werd in dit geval dus totaal niet aangesproken dus zou niet veel uitmaken)

try and amaze yourself.

edit op jouw edit:
Mja die reden had ik ook al wel grotendeels bedacht op 1 deel na ben ik het totaal met je eens. Ik weet namelijk die voordelen en nadelen tussen het var en instance name gebruik en ik heb dus één keer de var gebruikt omdat het uiteindelijk een stuk duidelijker was...
ik wou dus de inhoud van het veld later laten terugkomen dus het moest sowieso ergens in komen(var/array)
Waarom zou ik : varIets = tekstveld.text doen om later weer andertekstveld.text = varIets te zetten.
Het was geloof ik nog net iets anders maar je snapt vast wel wat ik wil zeggen |)

Dauntless
%Europe/Berlin %838 %2006, 21:07
Daar ligt het wel aan hoor...

Dus, geef het bovenste tekstvak de instancenaam 'tekst0' en het onderste de instance naam 'tekst1'. Verwijder bij beide de 'var' property.

Pas je AS aan zodat overal .text achter staat en zodat de instancenaam 'tekst0' en 'tekst1' wordt gebruikt:
stop();
//XML MENU
myData = new XML();
myData.ignoreWhite = true;
myData.onLoad = function(success) {
if (success) {
menuItem = this.firstChild.childNodes;
for (var i = 0; i<menuItem.length; i++) {
item = content_mc.attachMovie("itemClip", "itemClip"+i, i);
item._x = 0;
item._y = 15*i;
item.useHandCursor = false;
item.myName.text = menuItem[i].attributes.name;
item.myFile = menuItem[i].attributes.file;
item.myYear = menuItem[i].attributes.year;
item.myCreator = menuItem[i].attributes.creator;
item.myComment = menuItem[i].attributes.comment;
item.myCamera = menuItem[i].attributes.camera;
item.onRelease = function() {
unload(mc_photo);
loadMovie(this.myFile, mc_photo);
_root.mc_info.year = this.myYear;
_root.mc_info.creator = this.myCreator;
_root.mc_info.comment = this.myComment;
_root.mc_info.camera = this.myCamera;
_root.bt_i.visible = true;
};
item.onRollOut = function() {
this.gotoAndPlay(1);
};
item.onRollOver = function() {
this.gotoAndPlay(2);
};
}
}
};
playedFrames = 0;
//OnEnterFrame functies
onEnterFrame = function () {
playedFrames += 1;
//FUNCTIE1 - moving info menu
movey = (_root.mc_info.endPosy-mc_info._y)/5;
mc_info._y += movey;
movex = (_root.mc_info.endPosx-mc_info._x)/5;
mc_info._x += movex;
//FUNCTIE2 = preload
totaal = mc_photo.getBytesTotal();
geladen = mc_photo.getBytesLoaded();
if (geladen<totaal) {
tekst1.text = 'Loading image: '+geladen+' / '+totaal;
mc_photo._x = -610;
} else if (mc_photo._x<20) {
mc_photo._x += 10;
tekst1.text = 'Loading complete. Positioning image: '+-mc_photo._x*77;
} else {
tekst1.text = contentArray[1];
}
};
myData.load("myMenu.xml");
//INFO MENU
mc_info.endPosy = -500;
mc_info.endPosx = -500;
mc_info.close_mc.onPress = function() {
mc_info.endPosy = -500;
mc_info.endPosx = -500;
};
//NAMES
contentArray = ['<b><i>testing head</i></b>', 'testing the array'];
from0 = contentArray[0].length;
from1 = contentArray[1].length;
setInterval(textAnimation, 20);
function textAnimation() {
if (from0>0) {
from0 -= 1;
to0 = contentArray[0].length;
tekst0.htmlText = contentArray[0].substring(from0, to0);
}
if (from1>0) {
from1 -= 1;
to1 = contentArray[1].length;
tekst1.text = contentArray[1].substring(from1, to1);
//BUG IN FLASHCODE? tekst0 and tekst1 Could not be named tekst0 and tekst1. tekst1 would not show up.
}
}
//INFO
info.onPress = function() {
mc_info.endPosy = 300+random(150);
mc_info.endPosx = 55+random(150);
};

==> Het werkt.


Dan, verander instancenamen naar text0 en text1.
Pas overal in je AS 'tekst0' aan naar 'text0' en 'tekst1' naar 'text1'
stop();
//XML MENU
myData = new XML();
myData.ignoreWhite = true;
myData.onLoad = function(success) {
if (success) {
menuItem = this.firstChild.childNodes;
for (var i = 0; i<menuItem.length; i++) {
item = content_mc.attachMovie("itemClip", "itemClip"+i, i);
item._x = 0;
item._y = 15*i;
item.useHandCursor = false;
item.myName.text = menuItem[i].attributes.name;
item.myFile = menuItem[i].attributes.file;
item.myYear = menuItem[i].attributes.year;
item.myCreator = menuItem[i].attributes.creator;
item.myComment = menuItem[i].attributes.comment;
item.myCamera = menuItem[i].attributes.camera;
item.onRelease = function() {
unload(mc_photo);
loadMovie(this.myFile, mc_photo);
_root.mc_info.year = this.myYear;
_root.mc_info.creator = this.myCreator;
_root.mc_info.comment = this.myComment;
_root.mc_info.camera = this.myCamera;
_root.bt_i.visible = true;
};
item.onRollOut = function() {
this.gotoAndPlay(1);
};
item.onRollOver = function() {
this.gotoAndPlay(2);
};
}
}
};
playedFrames = 0;
//OnEnterFrame functies
onEnterFrame = function () {
playedFrames += 1;
//FUNCTIE1 - moving info menu
movey = (_root.mc_info.endPosy-mc_info._y)/5;
mc_info._y += movey;
movex = (_root.mc_info.endPosx-mc_info._x)/5;
mc_info._x += movex;
//FUNCTIE2 = preload
totaal = mc_photo.getBytesTotal();
geladen = mc_photo.getBytesLoaded();
if (geladen<totaal) {
text1.text = 'Loading image: '+geladen+' / '+totaal;
mc_photo._x = -610;
} else if (mc_photo._x<20) {
mc_photo._x += 10;
text1.text = 'Loading complete. Positioning image: '+-mc_photo._x*77;
} else {
text1.text = contentArray[1];
}
};
myData.load("myMenu.xml");
//INFO MENU
mc_info.endPosy = -500;
mc_info.endPosx = -500;
mc_info.close_mc.onPress = function() {
mc_info.endPosy = -500;
mc_info.endPosx = -500;
};
//NAMES
contentArray = ['<b><i>testing head</i></b>', 'testing the array'];
from0 = contentArray[0].length;
from1 = contentArray[1].length;
setInterval(textAnimation, 20);
function textAnimation() {
if (from0>0) {
from0 -= 1;
to0 = contentArray[0].length;
text0.htmlText = contentArray[0].substring(from0, to0);
}
if (from1>0) {
from1 -= 1;
to1 = contentArray[1].length;
text1.text = contentArray[1].substring(from1, to1);
//BUG IN FLASHCODE? text0 and text1 Could not be named text0 and text1. text1 would not show up.
}
}
//INFO
info.onPress = function() {
mc_info.endPosy = 300+random(150);
mc_info.endPosx = 55+random(150);
};

=> Het werkt ook

Je zou wel de laatste regel van je onEnterFrame moeten wegdoen want die zorgt er voor dat het textvak onmiddelijk gevuld wordt... (Ik begrijp de bedoeling niet juist van die regel).

try and amaze yourself.
Ik probeer je enkel te helpen hoor ... :(

renegeuze
%Europe/Berlin %845 %2006, 21:17
aargh hit me!
Ik heb ongeveer dat hele onEnterFrame gedeelte in een rijdende bus zitten maken en dat is blijkbaar niet goed voor het geheugen, ik was compleet vergeten dat ik die tekst tijdelijk in hetzelfde textvak wegschreef.

En try and amaze yourself is sowieso niet beledigend bedoelt ;)
Ik ben ook niet snel geiriteerd maar die hoofdletters en dikke letters die je gebruikte om me iets wijs te maken wat ik al lang wist waren wel irritant imho ^_^

Dauntless
%Europe/Berlin %847 %2006, 21:19
Sorry... Maar zo dringt het meestal het beste door :p. (En ik kan niet weten wat jij al lang weet hé :p).