At 9/16/20 02:50 PM, Edeshye wrote:
At 9/16/20 11:41 AM, Edeshye wrote:
At 9/11/20 10:50 AM, Gimmick wrote:
At 9/11/20 08:04 AM, Edeshye wrote:
Ok so i did this. I should click the pencil in order for the code to pop up am i right? when i did this, the code appeared as you wrote it, but without the function, of course. But it opened in another window, separated from the .fla i'm working on. Should i save it somewhere? i tried this as is, it didn't change anything, but i don't think the code is being applied, since it opened in a new window... i don't know.
Yes, you should save it in the project directory. Flash should usually create a template like the code I'd provided (without the stop() and visible=false though); below the "visible=false;" line can you add
if you see the console output window show "created" then the code should've executed. When that happens, though, depends on when it's actually present on the stage - which should be the frame that it's introduced.
it's a separated layer just for code (there are more then one code layer though, for example there is one for sounds)
Okay. Can you paste the code, if possible? Doesn't need to be verbatim - feel free to rename any variables as long as there's consistency.
Shiiiiiiiiit it finally worked. I'm sorry about the delay, i was working on the demo i just launched and i came back to this scene today. I made what you said with the constructor code, and made an if statement right there.
If (hand){visible=true;}
else{visible=false;}
It worked. Thanks a lot Gimmick, seriously!
hey @Gimmick, does the constructor code change anything in the instance name of the object or something? because now it compromised another code... it's showing that null object reference error :c
The class code (constructor, etc.) is entirely separate from the scene, so it shouldn't change anything else, especially not variable names. Sounds like Flash is unable to get the reference to something, whether due to an incorrect variable name, or due to something else. What happens when you call
trace(varName);
for each varName in your code right before the error occurs?
---
If all else fails, you could try adding movieclips from the class itself. It's a bit involved, but it should prevent any errors from occurring:
Create a document class for the movie (this is the recommended way to program in AS3 instead of frame scripts, from what I've heard and experienced). This can be done by clicking on an empty part of the stage and in the Properties panel, selecting the "Document class..." button (or something similar). In that, you can have five instances of a Scene, and each movieclip has its own class so that you can add it when needed. For example:
Document class:
package
{
import flash.display.*;
public class Main extends Sprite
{
private var scenes:Vector.<MovieClip>; //list of scenes as movieclips
public function Main()
{
//creates a new list of MovieClips
scenes = new <DisplayObject>[new Scene1(), new Scene2(), new Scene3(), new Scene4()]
showScene(0);
}
public function showScene(scene:uint):void
{
removeChildren();
addChild(scenes[scene])
}
}
}
Create a class called Scene (new ActionScript 3.0 File) in the "scenes" folder below the FLA and put this code in:
package scenes
{
import flash.display.*;
public class Scene extends Sprite
{
protected var objects:Vector.<MovieClip>; //will hold all scene objects
protected var locations:Array; //will hold all their locations
protected var active:Vector.<Boolean>; //will hold their state: visible & playing, or stopped
protected var sceneSwitchButtons:Vector.<DisplayObject>;
public function Scene()
{
stop()
}
protected function updateAll():void
{
var i:uint;
for(i = 0; sceneSwitchButtons && i < sceneSwitchButtons.length; ++i) {
addChild(sceneSwitchButtons[i])
}
for(var i:uint = 0; i < objects.length; ++i)
{
var currObject:MovieClip = objects[i];
currObject.x = locations[i][0];
currObject.y = locations[i][1]; //set x and y
if(active[i] != currObject.visible) //only runs code if there's a change
{
currObject.visible = active[i];
if(active[i]) {
currObject.play() //replace with gotoAndPlay(1) if you want it to restart each time it becomes visible
}
else {
currObject.stop();
}
}
}
}
}
}
And then create a class for each scene/frame you have (a new ActionScript 3.0 file again - not a movieclip with a class) and call it Scene1, Scene2, etc. and put this code in (it should be in the scenes folder again):
package scenes
{
import flash.display.*;
public class Scene1 extends Scene
{
public function Scene1()
{
//add your objects, eg person, woman, man, camera, TV
objects = new <MovieClip>[new Person(), new Woman(), new Man(), new Camera(), new TV()];
//and their locations - this you'll have to read the X and Y coordinate of each object in the property panel and copy it down here as [X, Y]
locations = [[0,0], [100, 10], [30, 30], [10, 10], [90, 70]];
active = new <Boolean>[true, true, true, true, false]; //TV is invisible and stopped
sceneSwitchButtons = new <DisplayObject>[new Scene2Button(), new Scene3Button()] //create scene switch buttons
updateAll(); //updates states of everything
}
}
}
Well, this got much longer than expected, and it's still not complete - there's listeners that need to be added to the buttons to switch scenes, make the hand visible and invisible, etc... This is waay more involved but it is much cleaner to implement and maintain. If you do end up using this method - assuming the problem hasn't been fixed - then let me know and I think I'll finish it.