mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-04 21:21:06 -05:00
Fixed renaming sound breaking references to that sound.
This commit is contained in:
parent
5132c96eb2
commit
e369c214ac
2 changed files with 28 additions and 6 deletions
|
@ -661,6 +661,17 @@ public class ScratchRuntime {
|
|||
// Script utilities
|
||||
//------------------------------
|
||||
|
||||
public function renameSound(s:ScratchSound, newName:String):void {
|
||||
var obj:ScratchObj = app.viewedObj();
|
||||
var oldName:String = s.soundName;
|
||||
if (obj.isCostumeNameUsed(newName)) return;
|
||||
s.soundName = newName;
|
||||
allUsesOfSoundDo(oldName, function (a:BlockArg):void {
|
||||
a.setArgValue(newName);
|
||||
});
|
||||
app.setSaveNeeded();
|
||||
}
|
||||
|
||||
public function clearRunFeedback():void {
|
||||
if(app.editMode) {
|
||||
for each (var stack:Block in allStacks()) {
|
||||
|
@ -731,6 +742,16 @@ public class ScratchRuntime {
|
|||
return result;
|
||||
}
|
||||
|
||||
public function allUsesOfSoundDo(soundName:String, f:Function):void {
|
||||
for each (var stack:Block in app.viewedObj().scripts) {
|
||||
stack.allBlocksDo(function (b:Block):void {
|
||||
for each (var a:BlockArg in b.args) {
|
||||
if (a.menuName == 'sound' && a.argValue == soundName) f(a);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function allCallsOf(callee:String, owner:ScratchObj):Array {
|
||||
var result:Array = [];
|
||||
for each (var stack:Block in owner.scripts) {
|
||||
|
|
|
@ -82,7 +82,7 @@ public class SoundsPart extends UIPart {
|
|||
editor.updateTranslation();
|
||||
SimpleTooltips.add(libraryButton, {text: 'Choose sound from library', direction: 'bottom'});
|
||||
SimpleTooltips.add(recordButton, {text: 'Record new sound', direction: 'bottom'});
|
||||
SimpleTooltips.add(importButton, {text: 'Upload sound from file', direction: 'bottom'});
|
||||
SimpleTooltips.add(importButton, {text: 'Upload sound from file', direction: 'bottom'});
|
||||
fixlayout();
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ public class SoundsPart extends UIPart {
|
|||
editor.x = contentsX;
|
||||
editor.y = 50;
|
||||
}
|
||||
|
||||
|
||||
private function addNewSoundButtons():void {
|
||||
var left:int = 16;
|
||||
var buttonY:int = 31;
|
||||
|
@ -185,7 +185,7 @@ public class SoundsPart extends UIPart {
|
|||
b.y = y;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
private function addListFrame():void {
|
||||
listFrame = new ScrollFrame();
|
||||
listFrame.setContents(app.getMediaPane(app, 'sounds'));
|
||||
|
@ -201,14 +201,15 @@ public class SoundsPart extends UIPart {
|
|||
private function nameChanged():void {
|
||||
currentIndex = Math.min(currentIndex, app.viewedObj().sounds.length - 1);
|
||||
var current:ScratchSound = app.viewedObj().sounds[currentIndex] as ScratchSound;
|
||||
current.soundName = nameField.contents();
|
||||
app.runtime.renameSound(current, nameField.contents());
|
||||
nameField.setContents(current.soundName);
|
||||
(listFrame.contents as MediaPane).refresh();
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Undo/Redo
|
||||
//------------------------------
|
||||
|
||||
|
||||
private function addUndoButtons():void {
|
||||
addChild(undoButton = new IconButton(editor.waveform.undo, makeButtonImg('undo', true), makeButtonImg('undo', false)));
|
||||
addChild(redoButton = new IconButton(editor.waveform.redo, makeButtonImg('redo', true), makeButtonImg('redo', false)));
|
||||
|
@ -220,7 +221,7 @@ public class SoundsPart extends UIPart {
|
|||
undoButton.setDisabled(!editor.waveform.canUndo(), 0.5);
|
||||
redoButton.setDisabled(!editor.waveform.canRedo(), 0.5);
|
||||
}
|
||||
|
||||
|
||||
public static function makeButtonImg(iconName:String, isOn:Boolean, buttonSize:Point = null):Sprite {
|
||||
var icon:Bitmap = Resources.createBmp(iconName + (isOn ? 'On' : 'Off'));
|
||||
var buttonW:int = Math.max(icon.width, buttonSize ? buttonSize.x : 24);
|
||||
|
|
Loading…
Reference in a new issue