Implemented isSoundNameUsed and fixed a copy-paste error

This commit is contained in:
Nathan Dinsmore 2014-06-24 18:56:23 -04:00
parent e369c214ac
commit 4552c5e0b0
2 changed files with 18 additions and 10 deletions

View file

@ -133,11 +133,19 @@ public class ScratchObj extends Sprite {
} }
public function isCostumeNameUsed(name:String):Boolean { public function isCostumeNameUsed(name:String):Boolean {
var existingNames:Array = []; name = name.toLowerCase();
for each (var c:ScratchCostume in costumes) { for each (var c:ScratchCostume in costumes) {
existingNames.push(c.costumeName.toLowerCase()); if (c.costumeName.toLowerCase() == name) return true;
} }
return (existingNames.indexOf(name.toLowerCase()) > -1); return false;
}
public function isSoundNameUsed(name:String):Boolean {
name = name.toLowerCase();
for each (var s:ScratchSound in sounds) {
if (s.soundName.toLowerCase() == name) return true;
}
return false;
} }
public function unusedCostumeName(baseName:String = ''):String { public function unusedCostumeName(baseName:String = ''):String {

View file

@ -664,7 +664,7 @@ public class ScratchRuntime {
public function renameSound(s:ScratchSound, newName:String):void { public function renameSound(s:ScratchSound, newName:String):void {
var obj:ScratchObj = app.viewedObj(); var obj:ScratchObj = app.viewedObj();
var oldName:String = s.soundName; var oldName:String = s.soundName;
if (obj.isCostumeNameUsed(newName)) return; if (obj.isSoundNameUsed(newName)) return;
s.soundName = newName; s.soundName = newName;
allUsesOfSoundDo(oldName, function (a:BlockArg):void { allUsesOfSoundDo(oldName, function (a:BlockArg):void {
a.setArgValue(newName); a.setArgValue(newName);