1/* 2 * Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program; if not, write to the Free Software 15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 * 17 */ 18 19/* 20 * Zou Lunkai, zoulunkai@gmail.com 21 * 22 * Tests about soft reference to sprites. 23 * 24 * Description: 25 * frame1: create an movieclip and rename it; 26 * frame3: remove the movieclip; 27 * frame5: re-create an movieclip with the original name. 28 */ 29 30 31.flash bbox=800x600 filename="soft_reference_test1.swf" background=white version=6 fps=12 32 33.frame 1 34 .action: 35 #include "Dejagnu.sc" 36 37 //create a movieclip 38 mcRef = this.createEmptyMovieClip("mc", 10); 39 check(typeof(mc)=='movieclip'); 40 check(typeof(mcRef)=='movieclip'); 41 check(mc == _level0.mc); 42 check(mcRef == _level0.mc); 43 44 //change the "_name" property 45 mc._name = 'changed'; 46 .end 47 48.frame 3 49 .action: 50 check(typeof(mc)=='undefined'); 51 check(typeof(mcRef)=='movieclip'); 52 check(mc == undefined); 53 check(mcRef == _level0.changed); 54 55 // remove the created moiveclip in frame1 56 changed.removeMovieClip(); 57 .end 58 59.frame 5 60 .action: 61 check(typeof(mc) == 'undefined'); 62 check(typeof(mcRef) == 'movieclip'); 63 check(mc == undefined); 64 check(mcRef.valueOf() == null); 65 66 //re-create a movieclip again, mcRef connects to the newly created movieclip 67 this.createEmptyMovieClip("mc", 20); 68 check(typeof(mc)=='movieclip'); 69 check(typeof(mcRef)=='movieclip'); 70 check(mc == _level0.mc); 71 // Gnash bug: 72 // Target of the sprite mcRef points to changed, so seeking 73 // for the new target fails (_level0.changed doesn't exist) 74 check(mcRef == _level0.mc); 75 .end 76 77.frame 7 78 .action: 79 // change the instance name again 80 mc._name = "changed_again"; 81 82 check(typeof(changed_again)=='movieclip'); 83 check(mcRef != _level0.changed_again); 84 85 check(mc == undefined); 86 check(typeof(mcRef)=='movieclip'); 87 check(mcRef.valueOf() == null); 88 89 // change the instance name back 90 mc._name = "mc"; 91 check(typeof(mc)=='undefined'); 92 check(mc == undefined); 93 94 check(typeof(mcRef)=='movieclip'); 95 check(mcRef.valueOf() == null); 96 97 // Release resources after testing 98 delete mc; 99 delete mcRef; 100 changed_again.removeMovieClip(); 101 .end 102 103 104// seperate tests in frame9 105.frame 9 106 .action: 107 _root.createEmptyMovieClip("mc1", 30); 108 mc1._name = "mc2"; 109 mcRef = mc2; 110 111 check(typeof(mcRef)=='movieclip'); 112 check_equals(mcRef.getDepth(), 30); 113 check(mcRef == _level0.mc2); 114 115 mc2.removeMovieClip(); 116 _root.createEmptyMovieClip("mc2", 40); 117 118 check(typeof(mcRef)=='movieclip'); 119 // Gnash bug: 120 // Target of the sprite pointed to by mcRef is 121 // not the one used on creation (_level0.mc1) but the one 122 // subsequently changed to by effect of _name assignment: _level0.mc2. 123 // Thus, when finding a *new* DisplayObject (the old one was unloaded) 124 // we find the *new* _level0.mc2. 125 // Should be fixed in the same way as for the bug exposed in frame 5 126 check(mcRef.valueOf() == null) 127 128 // release resources after testing 129 delete mcRef; 130 mc2.removeMovieClip(); 131 .end 132 133// seperate tests in frame11 134.frame 11 135 .action: 136 mcContainer = new Array(10); 137 i = 0; 138 MovieClip.prototype.onConstruct = function () 139 { 140 mcContainer[i++] = this; 141 note("Constructed "+this+" in depth "+this.getDepth()+" and assigned to mcContainer["+(i-1)+"]"); 142 }; 143 _root.createEmptyMovieClip("mc1", 50); 144 _root.createEmptyMovieClip("mc1", 51); 145 check_equals(mcContainer[0].getDepth(), 50); 146 check_equals(mcContainer[1].getDepth(), 51); 147 check_equals(mc1.getDepth(), 50); 148 149 mc1._name = "mc2"; // char at depth 50 changes name 150 mcRef = mc2; // mcRef now points to char at depth 50, and target _level0.mc2 151 152 check(typeof(mcRef)=='movieclip'); 153 check_equals(mcRef.getDepth(), 50); 154 check(mcRef == _level0.mc2); 155 156 mc2.removeMovieClip(); 157 _root.createEmptyMovieClip("mc2", 60); 158 159 check(typeof(mcRef)=='movieclip'); 160 161 // Gnash bug: 162 // Still the same bug: the ref uses *current* target instead of the one 163 // as of creation time. 164 check(mcRef == _level0.mc1); 165 166 _root.totals(38); 167 stop(); 168 .end 169 170.end 171 172