From 4552c5e0b0e0c4e9ab72af3e2b1947a0a1732b0a Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Tue, 24 Jun 2014 18:56:23 -0400 Subject: [PATCH] Implemented isSoundNameUsed and fixed a copy-paste error --- src/scratch/ScratchObj.as | 26 +++++++++++++++++--------- src/scratch/ScratchRuntime.as | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/scratch/ScratchObj.as b/src/scratch/ScratchObj.as index 4313dee..3e99861 100644 --- a/src/scratch/ScratchObj.as +++ b/src/scratch/ScratchObj.as @@ -25,23 +25,23 @@ package scratch { import blocks.*; - + import filters.FilterPack; - + import flash.display.*; import flash.events.MouseEvent; import flash.geom.ColorTransform; import flash.utils.*; - + import interpreter.*; - + import scratch.ScratchComment; import scratch.ScratchSprite; import translation.Translator; - + import util.*; - + import watchers.*; public class ScratchObj extends Sprite { @@ -133,11 +133,19 @@ public class ScratchObj extends Sprite { } public function isCostumeNameUsed(name:String):Boolean { - var existingNames:Array = []; + name = name.toLowerCase(); 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 { diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index 2b99651..29b9750 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -664,7 +664,7 @@ public class ScratchRuntime { public function renameSound(s:ScratchSound, newName:String):void { var obj:ScratchObj = app.viewedObj(); var oldName:String = s.soundName; - if (obj.isCostumeNameUsed(newName)) return; + if (obj.isSoundNameUsed(newName)) return; s.soundName = newName; allUsesOfSoundDo(oldName, function (a:BlockArg):void { a.setArgValue(newName);