Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Mask Problems Adding/removing



I'm using a movieclip in the mask layer so I can change the x & y coordinates, or edit the diameter, to create a mobile spotlight effect, but I can't seem to get the mask to go completely off (black) or switch off (normal lights on). I've tried remove movieclip but nothing happens.Do masks have some kind of separate code and layers I need to know about?



Adobe > ActionScript 1 and 2
Posted on: 12/26/2008 08:10:02 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Removing And Adding
Hi there,

I'm new with actionscript 3 and i'm trying to understand how the adding and removing works with objects in as3.

I have this:


Code:
var myArray:Array = [["asdf"],["qwer"],["qwer"]];
for (var i:int=0;i<myArray.length;i++)
{
var myObject:Object= new Object();

myObject["myLabel_"+i] = new Hallo();
myObject["myLabel_"+i].name = +i;
myObject["myLabel_"+i].y = 10 + i * (myObject["myLabel_"+i].height + 10);

addChild(myObject["myLabel_"+i]);

myObject["myLabel_"+i].addEventListener(MouseEvent.CLICK, myData);
}

function myData(event:MouseEvent):void
{
var string:String = event.currentTarget.name;
trace(this.parent);
trace(event.currentTarget.name);
//this.parent.removeChild(this);
//removeChild(myObject["myLabel_"+i]);
}
But how do i remove the object that is being clicked?
so if you click on object myObject["myLabel_1"] it wil be removed

hope someone can help

Adding And Removing Listeners
Hi!
Can anyone get this fla to work? I'm trying to first add a key listener and trace if space is pressed, then I want to remove that listener and replace it with another that traces if enter is pressed.
Thanks!

Need Some AS Assistance With Adding And Removing Mc's
ok... i found some code in some random thread while i was doing random searched.. i believe jbum actually wrote the original... anyway.. i chopped it up and simplified it so i could use it as a masking effect. What i can't figure out... is how to reverse the effect to remove it (which will occur when mc is clicked to move to another section... ideally.. mask wil remove itself and then progress to preloader, then once swf is loaded, mask will be applied and swf will play.) any ideas?... below is the code i have that works for now... just created a solid color rectangle to act as container with swf file.

Code:
MovieClip.prototype.drawBox = function(clr, x, y, w, h) {
this.beginFill(clr, 100);
this.moveTo(x, y);
this.lineTo(x+w, y);
this.lineTo(x+w, y+h);
this.lineTo(x, y+h);
this.lineTo(x, y);
this.endFill();
};
_root.createEmptyMovieClip("base", 1);
base.drawBox(0xFF0000, 0, 0, Stage.width, Stage.height);
//
bars = 27; //the clip size i need to mask will be 540 x 240 || 540/20 = 27
_root.createEmptyMovieClip("mask", _root.getNextHighestDepth());
for (i=0; i<bars; ++i) {
var mc = mask.createEmptyMovieClip('square'+i, i);
mc._x = mc._x+i*20;
mc._y = 0;
mc.drawBox(0x4A5263, 210, 10, 20, 240); //container clip _x = 210 & _y = 10
// 20 is final width of rect and 240 is final height
mc._xscale = 0; // starts scale at 0
mc._yscale = 0;
a = i*2*Math.PI/bars;
mc.dS = 100;
mc.idx = i;
mc.startTime = getTimer();
mc.onEnterFrame = function() {
if (getTimer()-this.startTime>this.idx*100) {
//var da = this.dA-this._alpha;
this._xscale += (this.dS-this._xscale)/6;
this._yscale = this._xscale+10;
this._x = Stage.width/2+this._x-10(a-getTimer()*.0001)*100;
this._y = Stage.height/2+this._y(a-getTimer()*.0001)*100;
}
// i thought i could use some sort of if statement here... to say if the mask isn't applied
// apply it... if it is applied... remove it. but i'm retarded
};
}
base.setMask(mask);

Adding/removing Listeners
Hi!
I am creating 5 instances of a custom class. Then I’m adding an event listener to each of those instances, they all point to the same function. Then in that function I’m removing the event listener. The purpose of the function is it creates 5 rooms in a game and loads in the background. The event is dispatched from inside the room when the background image has loaded. If I don’t use the event listeners then everything works fine. All 5 rooms load. If I add the event listeners to them all then only two of them actually load and get dispatched.

Here is the function that creates the room instances and sets up the listeners

Code:
private function loadRooms(startRoomID:int):void
{
_roomsCurrentlyLoading = [];
var startRoom:Room = Main(parent).getRoomRefs()[startRoomID];
var exits:Object = startRoom.getExits();

if (!startRoom.getIsLoaded())
{
startRoom.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
startRoom.loadMe("center", startRoom);
_roomsCurrentlyLoading.push(startRoom);
}
var room:Room;

if (exits["north"] != -1)
{
room = Main(parent).getRoomRefs()[exits["north"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("north", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["east"] != -1)
{
room = Main(parent).getRoomRefs()[exits["east"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("east", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["south"] != -1)
{
room = Main(parent).getRoomRefs()[exits["south"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("south", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["west"] != -1)
{
room = Main(parent).getRoomRefs()[exits["west"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("west", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

trace(_roomsCurrentlyLoading);
}
And here is the event listener:

Code:
public function onRoomLoaded(e:RoomEvent):void
{
trace("target: " + e.target.getId());
e.target.removeEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
}
Then inside of the loadMe function in the room, I load the background image using the Loader class. When the complete event from there is called, I also dispatch ON_ROOM_LOADED event.
I haven’t worked much in AS3 so I’m not sure if my problem is just because I don’t yet understand how everything works yet.

Adding And Removing Children
I was going to pose a question, but I think I answered it myself. Still, it took quite a bit of ironing out to get it to run without errors. I thought this might be instructive to others, so I'm going to post it anyway.

Here's the deal: I'm working on a maze game, and I'm making a "reward" screen for solving the maze. It's kind of a splash screen, and I wanted to add a bunch of instances of a heart movie clip, animate them scaling up, then maybe remove them again. That was the part I was having trouble with, doing the removeChild thing. I thought if I can add them with addChild, why can't I remove them with removeChild? I kept getting errors!

Here's the code:

ActionScript Code:
var timer:Timer = new Timer(100, 50); //make 50 hearts, 100 ms apart
timer.addEventListener(TimerEvent.TIMER, addHearts);
timer.start();

function addHearts(event:TimerEvent):void {
    var heart:Heart = new Heart();
    heart.x = Math.random() * stage.stageWidth;
    heart.y = Math.random() * stage.stageHeight;
    heart.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    stage.addChild(heart);
}

function enterFrameHandler(event:Event):void {
    var clip:Heart = Heart(event.target);
    if (clip.scaleX < 4) {
        clip.scaleX += .1;
        clip.scaleY += .1;
    } else {
        //this next line is the one that was needed:
        clip.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
        stage.removeChild(clip);
    }
}
If you comment out the line that removes the event listener, you get errors. So I guess you can't remove a child if it's got an active listener. The above code just needs a heart movie clip in the library with a linkage identifier of Heart. Or, you can dl the attached file to observe.

Adding And Removing Loaders
Hi, all. I'm kinda new to AS3 so I'm having some issues with loading external swfs into a main swf movie using loader().

here is my code of Frame 1 (Actions layer):

var link:URLRequest = new URLRequest("home.swf");

var loader:Loader = new Loader();
loader.load(link);
addChild(loader);

What I am trying to do is load swfs using a simple navigation system.

I have the following MC Buttons:
home_mc, services_mc, products_mc, about_mc and contact_mc.

I'm using event listeners to handle a mouse click event once any of these buttons are clicked as follows

myButton_mc.addEventListener(MouseEvent.CLICK, loadHomePage)

function loadHomePage(event:MouseEvent):void
{

var link:URLRequest = new URLRequest("home.swf");

var loader:Loader = new Loader();
loader.load(link);
addChild(loader);
}

Now the problem is that once the first swf "home.swf" is loaded at run time, the user is unable to click my button and re-load the home.swf or any other wf. Which shoud replace the current swf that is loaded, but it doesn't. It just adds another instance of the swf "home.swf" a top of the swf on the stage.

Can anyone tell me of a better way to load and unload external swfs using a navitations system to cycle through the swfs to load. (e.g Clicking a button to load the desired swfs and at the same time unload the currently loaded swf.)

Please help!

xion

Adding & Removing Listeners
Well, I've been searching this site for a little while trying to wrap my head around my problem but to no luck. My apologies if this is a repetitve subject or if it's kind of "newbie"-ish of me but, I am in a jam over here.

Basically, I'm trying to go from frame 1 to frame 2 to frame 3 (for example) using certain keystrokes. Starting from frame 1 my code looks like this:

keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(85)) {
gotoAndPlay("2");
}
};
Key.addListener(keyListener);

(85 is the key code for the letter "c")

And that works fine. But, now that I'm on frame 2, I want a different keystroke to send me to frame 3. So my code looks like this:

keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(80)) {
gotoAndPlay("3");
}
};
Key.addListener(keyListener);

(80 is the key code for the letter "u")

And that works too. However, the previous keystroke (85 or "c") will send me to frame 3 as well. I only want one keystroke to send me to frame 3, not both. I've tried looking around the site to see if a removeListener would work but I can't figure it out.

Any ideas? I could really use the help.

THANKS in advance!!!

Adding/Removing Components...
I am working with components for the first time....
Now, currently, i am creating components with the attachMovie(), it works, but is it the right way to do it? The reason i ask is because i cant remove the components with removeMovieClip(), how do you remove them?
Thanks!

Adding/Removing Listeners
Hi guys, ok I have movieclips which have timeline animations on them as they are animated buttons. So, I want to set up the following listeners...

MOUSE_OVER -> Play the movieclip and delete the enterframe when it hits the last frame
MOUSE_OUT -> Rewind the movieclip
CLICK -> Delete the listener so basically the button is "selected" and the MOUSE_OUT won't happen when the user takes their mouse off the button.

Now it's the CLICK handler I'm having trouble with. I'm not sure if I quite understand removing listeners yet! Anyways, here's my code. The current status is that the MOUSE_OUT action still happens even after the button has been clicked...


Code:
package com {
import flash.events.Event;
import flash.events.MouseEvent;

public class MovieClipButton {
public function MovieClipButton(target) {
target.addEventListener(MouseEvent.MOUSE_OVER, eventHandler);
target.addEventListener(MouseEvent.MOUSE_OUT, eventHandler);
target.addEventListener(MouseEvent.CLICK, eventHandler);
}

public function eventHandler(e:MouseEvent) {
switch (e.type) {
case "mouseOver" :
trace("OVER");
e.target.addEventListener(Event.ENTER_FRAME, doPlay);
break;
case "mouseOut" :
trace("OUT");
e.target.addEventListener(Event.ENTER_FRAME, doRewind);
break;
case "click" :
trace("CLICK");
e.target.removeEventListener(MouseEvent.CLICK, eventHandler);
break;
}
}

public function doPlay(e:Event) {
e.target.gotoAndStop(e.target.currentFrame+1);
if (e.target.currentFrame == e.target.totalFrames) {
e.target.removeEventListener(Event.ENTER_FRAME, doPlay);
}
}

public function doRewind(e:Event) {
e.target.removeEventListener(Event.ENTER_FRAME, doPlay);

e.target.gotoAndStop(e.target.currentFrame-1);
if (e.target.currentFrame == 1) {
e.target.removeEventListener(Event.ENTER_FRAME, doRewind);
}
}
}
}
I really hope someone can help. Thanks guys!

PS: One other thing... is there a way to trace out all the listeners (and maybe some data about them, type etc) currently on an object?

Adding/Removing Components...
I am working with components for the first time....
Now, currently, i am creating components with the attachMovie(), it works, but is it the right way to do it? The reason i ask is because i cant remove the components with removeMovieClip(), how do you remove them?
Thanks!

Adding And Removing Values In A Variable
I have 4 buttons, each button has 2 options.

example for button 1:

if you click it once you add "item1" to the var "itembox"
if you click it again it substract "item1" from the var "itembox"

I want to be able to add and substract different assigned values from var "itembox" but my code its not working properly.


here is my code TO ADD:

_root.itembox = _root.itembox+String(_root.app1+", ");

here is my code TO SUBSTRACT:

_root.itembox = _root.itembox-String(_root.app1+", ");



can anyone tell me how can I get this to work properly?
thanks!

Adding And Removing Images With Actionscript
I want to be able to add or subtract interactively from a number then use this number to resize a coloured section in a rectangle. Basically I want to be able to simulate adding and removing coloured water from a glass jar. As I add more so the coloured bit gets bigger. As I take some out it gets smaller! I can use a dynamic slider to set the amount up and then transfer to the glass jar!
I'm sure that this can be done using actionscript but I haven't yet been able to work out how! Any ideas gratefully received!

Removing And Adding Moving Clips
I am making a game, were you can move a person to a car, and by being in a center zone, and pressing enter, the man enters the car. I have a movable man, and a movable car, and i can make the zone, and have the zone acknowlegde when i am standing there and hitting enter.

what i want to know is how i make the movable man disappear, play little animation of him entering the car, and then replacing the "fake car" with the car that can actually move.

so i am looking at, pretty much, replacing on movieclip with another, how would i do this?

any help would be great, thanks.

Problems Adding/removing External SWF
On my main timeline, I have a list of buttons that each load an external SWF when pressed. When a button is pressed, the SWF loads into a movieclip on the main timeline, and the list dissappears (so only one is loaded at a time). The main timeline moves to a frame with a back button. When the back button is pressed, I'm trying to remove the loaded SWF and make the menu visible again to load another SWF.

This all works, but when I get back to the menu and try to load a new SWF, I get the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at CrystalBall/PL_LOADING()

CrystalBall being the first SWF I tried to load. The error fires like, four or five times too. I know it has something to do with the code trying to remove the loader before it loads it again, but I'm not sure how to fix it


Code:
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.*;

public class Splash extends MovieClip {
var gameLoader:Loader = new Loader();

function Splash() {
// ensures that games load from top left corner
gameHolder.x = 0; //gameHolder is already on timeline
gameHolder.y = 0;
}

function loaded() { //called after preloader
// game buttons
game1.addEventListener(MouseEvent.CLICK, loadGame);
game2.addEventListener(MouseEvent.CLICK, loadGame);
game3.addEventListener(MouseEvent.CLICK, loadGame);

function loadGame(evt:MouseEvent) {
gameHolder.addChild(gameLoader);
var gamePath = evt.target.name+".swf";
var game:URLRequest = new URLRequest(gamePath);
gameLoader.load(game);
gameLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameLoad);
function onGameLoad() {
gameLoaded = true;
gameLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onGameLoad)
}
MovieClip(root).gotoAndStop("play now"); // reveals back button
}

backBtn.addEventListener(MouseEvent.CLICK, backToMenu);
function backToMenu(evt:MouseEvent):void {
gameLoader.unload();
gameHolder.removeChild(gameLoader);
gameLoaded = false;
backBtn.visible = false;
MovieClip(root).gotoAndStop("start"); // shows menu
}
}
}
}
I've searched the net and found similar problems, but no solutions that seemed to work for me.

Adding/removing/sorting Infinite Mc's
i'm trying to make a program such that if a button is pressed it adds movie clips to the stage (that move around, and can be dragged and such while there)
and when you drag the movie clips to a certain area they dissapear

i want it so there can potentially be infinite movie clips added
and there will be a counter as to how many are on the stage at any one time

here are my main functions for creating and removing the movie clips:

Code:
function create_p(i){
p_mc[i]=_root.createEmptyMovieClip("xMc"+random(5000000), i);
p_mc[i].loadMovie("p"+37+".png");
p_count += 1;
}


MovieClip.prototype.remove_p = function(i){

this.unloadMovie();
p_mc.splice(i,1)
p_count -= 1;
}
what happens is if you remove a movie clip then try to add a new one, the last visable movie clip is overwritten for some odd reason...

for example:
there are 5 mc's, you remove one, there are now 4
now you add 1... it overwrites #4 so that there are only 4 mc's instead of 5! (Even thou the counter says there is 5)

what the heck am i doing wrong? it's been driving me crazy

Adding And Removing Several MovieClips At A Time
Hi again!

First of all, I'd like to apologize in advance if I don't use the proper vocab or you guys don't understand what I'm saying - I'm quite new to as3...

Okay, so here is my situation: I have a MovieClip symbol. What I want to have happen is that when I press a button, many copies of the MovieClip will be drawn on the stage (I know how to do the button, thats not a problem). Then, I will have another button and pressing it will make some (not all) of those movie clips be deleted.

Now, what I have so far is this: pressing the button calls a function where I have a "for loop". That loop creates many copies of the MovieClip with "addChild". All that is working. What I haven't got working is how to delete more than one MovieClip from the stage (removeChild only removes the last MovieClip put on the stage). Should I be doing this with arrays? Or is there another method?

If anyone can point me in the right direction, I'll be very thankful!
Beefpuff

Adding/removing Event Listeners
Hi!
I am creating 5 instances of a custom class. Then I’m adding an event listener to each of those instances, they all point to the same function. Then in that function I’m removing the event listener. The purpose of the function is it creates 5 rooms in a game and loads in the background. The event is dispatched from inside the room when the background image has loaded. If I don’t use the event listeners then everything works fine. All 5 rooms load. If I add the event listeners to them all then only two of them actually load and get dispatched.

Here is the function that creates the room instances and sets up the listeners

Code:
private function loadRooms(startRoomID:int):void
{
_roomsCurrentlyLoading = [];
var startRoom:Room = Main(parent).getRoomRefs()[startRoomID];
var exits:Object = startRoom.getExits();

if (!startRoom.getIsLoaded())
{
startRoom.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
startRoom.loadMe("center", startRoom);
_roomsCurrentlyLoading.push(startRoom);
}
var room:Room;

if (exits["north"] != -1)
{
room = Main(parent).getRoomRefs()[exits["north"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("north", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["east"] != -1)
{
room = Main(parent).getRoomRefs()[exits["east"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("east", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["south"] != -1)
{
room = Main(parent).getRoomRefs()[exits["south"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("south", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["west"] != -1)
{
room = Main(parent).getRoomRefs()[exits["west"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("west", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

trace(_roomsCurrentlyLoading);
}
And here is the event listener:

Code:
public function onRoomLoaded(e:RoomEvent):void
{
trace("target: " + e.target.getId());
e.target.removeEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
}
Then inside of the loadMe function in the room, I load the background image using the Loader class. When the complete event from there is called, I also dispatch ON_ROOM_LOADED event.
I haven’t worked much in AS3 so I’m not sure if my problem is just because I don’t yet understand how everything works yet.

Adding And Removing Content In Array
hi, I'm trying to test if a button, after I've pressed it, is in an Array and if it is, then it removes it self from the Array, otherwise it will add itseelf in the Array.

my code is:

Code:
var myArray = new Array();

mc1.onPress = function() {
for(var i = 0; i<myArray.length; i++) {
if(myArray[i] == mc1) {
myArray.splice(i, 1);
trace("object mc1 has deleted from myArray");
}
if((i >= myArray.length) && (myArray[i] != mc1))
myArray.push(mc1);
i = myArray.length;
trace("object mc1 has imported in myArray");
}
}
And the code doesn't work, so how should I write it?

Thanks.

Programmatically Adding/removing Keyframes
Is there a way to programmatically add/remove keyframes? Say I have a FLA with two keyframes but want to add a third if a certain criteria is met or depending on the value saved in a variable. Any guidance is appreciated . Thanks!!!

Removing And Adding Movie Clips
Hey guys,

I am making a platform game and I decided to do the scrolling background by cacheing it so I could repeat the background and it would make it faster. But the actual platforms, I will put in another mc, which I will put the same code as the moving background so it moves but I'm not going to have it repeat so I need to make a lot of these for a very long level. I will store these off stage but I know this will slow it down significantly so any ideas on how to store these movie clips somewhere like the library and call them up when the character is approaching it and removing the other mc of platform so it makes the game run faster?

Please help!! Thanks

Adding/Removing External Images
Seems like a pretty simple issue but I can't seem to get it right. I'm using the addChild method to place an externally loaded image in a frame. When the user navigates away from that frame, I want to remove the image (and presumably load another image into the new frame)

I've tried this with the code below but the image isn't removed when the user click away from that frame (first method). I'm thinking that using the MouseEvent.Click isn't the best way to accomplish this.

Also tried it using the second method. The image is removed when I click away to go to another frame but when I click to a third frame I get the follow error message:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at main_fla::MainTimeline/outClick()

I know this is pretty basic issue but if anyone has some tips I would greatly appreciate it!










Attach Code

//first method
var image1:URLRequest = new URLRequest("images/image1_full.jpg");
var image1Loader:Loader = new Loader();
image1Loader.load(image1);

this.addEventListener(Event.ENTER_FRAME, image1Enter);

function image1Enter(event:Event)
{
image1Loader.x = 588.1;
image1Loader.y = 105;
addChild(image1Loader);
}

this.addEventListener(MouseEvent.CLICK, outClick);

function outClick(event:MouseEvent):void
{
removeChild(image1Loader);
}

//second method
var image1:URLRequest = new URLRequest("images/image1_full.jpg");
var image1Loader:Loader = new Loader();
image1Loader.load(image1);

image1Loader.x = 588.1;
image1Loader.y = 105;
addChild(image1Loader);

this.addEventListener(MouseEvent.CLICK, outClick);

function outClick(event:MouseEvent):void
{
removeChild(image1Loader);
}

























Edited: 11/28/2007 at 07:12:38 PM by cutgrs930

Best Practices For Adding/removing Elements
Hey, all!

I thought i'd start this thread to uncover peoples habits and practices when it comes to the simple operation of adding and removing elements on stage. I ask because there are so many alternatives, and I keep wondering what might be the best/most eficcient way of doing it. Let me explain by giving an example:

Your user has chosen to click that flashing button that says "Sign up for our mailing list" and you need to prompt the user for a valid e-mail address by presenting him/her with an alert box on top of everything else. Do you...

a) gotoAndStop("alertbox");

b) alertBox_mc.gotoAndStop("show");

c) this.attachMovie("alertBox_mc", "alertBox_mc", 99);

d) alertBox_mc._x = 200;
alertBox_mc._y = 200;
(assuming mc was first placed off stage)

e) alertBox_mc._visible = true;

f) alertBox_mc._alpha = 100;

or

g) this.createEmptyMovieClip("alertBox_mc", 99);
alertBox_mc.createTextField("header", ....
...and so on (create everything is from AS)

...or anything else you might prefer. Of course, different situations call for different solutions, but which one do you find yourself using the most?

Option a and c are my personal weapons of choice, but they come with a few drawbacks. I.e. option a would require you to work with a potentially large number of mc's on stage that in idle state only display as tiny, white dots (while authoring), and when there are 10 of them on stage they become hard to tell apart. Often times I find myself clicking 4 or 5 of them before finding the right one.

Please contribute!

Øyvind, Oslo, Norway.

Adding And Removing Childs - How To Do It Safe
Hello Kirupa Forum,,

I got a problem with something, hope if someone know the awser.

I did a site navigation based on frames. When the site is on frame1, it addChild of a movieclip called 'mc'. But when I go to frame 2, I dont need mc anymore, so I call removeChild to remove the undesired mc. But when I go from another frame and step in frame 2 again, the mc does no exist and the code halts on the removeChild line. Someone have a good idea?

How Can I Keep Adding And Removing The Same Content To Container?
Hello,
I'm trying to make an order form that would be closed from a button. I know this is simple question, but how the odd thing is that when I press the close button named btn the first time everything works fine. The second time I open the form and close it I get an error message:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild() at MethodInfo-994()

The third time I open and close the form I get the error two times. The fourth time I open and close the form I get the error four time etc.. I think you get the idea... The problem must be somewhere in removing the child and then adding it again and removing. Can someone help me please? Here is the code:


var container:Sprite = new Sprite();
addChild(container);
var forma1:Loader = new Loader();
var urlReq:URLRequest = new URLRequest("file.swf");
forma1.load(urlReq);
forma1.contentLoaderInfo.addEventListener(Event.CO MPLETE, loaded);

function loaded(event:Event):void
{
container.addChild(forma1);
btn.addEventListener(MouseEvent.CLICK, closeforma);
function closeforma(event:MouseEvent):void
{
container.removeChild(forma1); // I also tried removeChild(container) without any better luck....
}
}

Adding/removing Event Listeners
Hi!
I am creating 5 instances of a custom class. Then I’m adding an event listener to each of those instances, they all point to the same function. Then in that function I’m removing the event listener. The purpose of the function is it creates 5 rooms in a game and loads in the background. The event is dispatched from inside the room when the background image has loaded. If I don’t use the event listeners then everything works fine. All 5 rooms load. If I add the event listeners to them all then only two of them actually load and get dispatched.

Here is the function that creates the room instances and sets up the listeners

Code:
private function loadRooms(startRoomID:int):void
{
_roomsCurrentlyLoading = [];
var startRoom:Room = Main(parent).getRoomRefs()[startRoomID];
var exits:Object = startRoom.getExits();

if (!startRoom.getIsLoaded())
{
startRoom.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
startRoom.loadMe("center", startRoom);
_roomsCurrentlyLoading.push(startRoom);
}
var room:Room;

if (exits["north"] != -1)
{
room = Main(parent).getRoomRefs()[exits["north"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("north", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["east"] != -1)
{
room = Main(parent).getRoomRefs()[exits["east"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("east", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["south"] != -1)
{
room = Main(parent).getRoomRefs()[exits["south"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("south", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

if (exits["west"] != -1)
{
room = Main(parent).getRoomRefs()[exits["west"]];
if (!room.getIsLoaded())
{
room.addEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
room.loadMe("west", startRoom);
_roomsCurrentlyLoading.push(room);
}
}

trace(_roomsCurrentlyLoading);
}
And here is the event listener:

Code:
public function onRoomLoaded(e:RoomEvent):void
{
trace("target: " + e.target.getId());
e.target.removeEventListener(RoomEvent.ON_ROOM_LOADED, onRoomLoaded);
}
Then inside of the loadMe function in the room, I load the background image using the Loader class. When the complete event from there is called, I also dispatch ON_ROOM_LOADED event.
I haven’t worked much in AS3 so I’m not sure if my problem is just because I don’t yet understand how everything works yet.

Adding And Removing Linked Symbols Using AS
I asked a question regarding this yesterday, to no avail. I'm still looking for suggestions. So, All I'll ask, is how do you programmatically add and remove your linked library symbols to and from your movie? in an orderly fashion. I'm not looking for like the generic answer of var whatever:whatever = new Whatever();.. I'm looking for a technique that helps tween the instance in, organize which instances are added, and tweens out and removes at the proper event. Again, I know this is vague, but if you have a second.. anything would help. thanks..

or you could check my last post to get a better idea of what i'm looking of doing.. it's called website page change or something like that.

Adding & Removing Items From A List Box
Hi - I am attempting to add and/or remove the selected item in a list box with a remove button. Does anyone know how to target the selected item and remove it?

I am going off of the tutorial from Kirupa.com - advanced Flash MX tutorials - create a list box.

If someone can help, that would be awesome.

Removing Movie Clips And Adding Them Again
Hello, I have a question about removing movie clips in as3.

So how do I remove a movie clip and then add it to the stage again?

Say I'm creating something like:
Code:

function createMovie():void
{
      var mMask:MovieClip = new MovieClip;
      addChild(mMask);
}

And I want to remove the previous instances of this mMask movie, so theres only one mMask movie on the stage, something like this:
Code:

function createMovie():void
{
      mMask = null;
      var mMask:MovieClip = new MovieClip;
      addChild(mMask);
}

But of course this won't work, so I'm asking what's the proper method of doing it?
Thank you.

Adding Or Removing Time From Middle Of Movie
I have a long involved, interactive movie. I've noticed that I forgot to include some things that belong in the middle of the movie. Or I have some thing in the middle of the movie that I no longer need and want to remove. What is the best way to do this?

This is not a problem for a simple movie: 100 frames and just one layer. You just go up to your time line and move stuff around.

This seems to be much more of a problem in a large movie: 1000's of frame and say 50 layers. Moving items on a single layer is, again, relatively easy. It's keeping all the other layers in synch that is difficult (at least for me).

Using ActiongScript, I can put a gotoAndPlay(some_frame_label) and jump about the movie, thereby "adding" time in the middle or perhaps skipping over a section of the movie. While this is okay for a few changes and the movie displays properly, the underlying structure soon gets ugly. Get too many such edits and your movie may not be maintainable.

As an analogy: in an Excel spreadsheet, you can insert or delete a row. When you do, everything to the right moves over or back to accomodate the change. In Flash MX, I would like to be able to go to frame 100 and insert 10 frames of space (or remove them for that matter). This would allow me to insert things I've forgotten or remove things no longer needed.

Again, this is no big deal with one layer and 100 frames. It is an entirely different matter with potentially 10s to 100s of layers and 1000s to 10,000s of frame.

Removing/adding Parts Slideshow Tutorial
Ok,
Here's what I have, I am trying to make a calendar of events that automatically changes from one month to the next just like a photo slide show. But.... I don't need images just the date of the event, location and link to location. So I have it partially working since I have added the date and location to the caption tag but I still need a link location to end up on the page. I'm new to xml so I don't know what to get rid of and what to keep.

Any thoughts...

Adding And Removing Opaque Child Seems To Layer?
Evening all,
I come humbly before you to ask for assistance.

I currently have a map beacon on my map (natch) and have a toggle button that shows the user how far their character can move, displayed as a 0.2 opaque circle, centred on them.

I want this to be togglable, to prevent lots of data clouding the UI. I have made a button in my interface that, depending on the button's state (up/down) will hide/show the circle.

I am using removeChild() to remove it, and also set it to null as recommended elsewhere. Delete doesn't work because of it's nature (dynamically drawn from a value in database)

I then use a method of my Map class to redraw/attach the circle. I thought this all worked fine, until I just started flipping the button repeatedly.. and noticed the colour gradually getting darker.

I check each button press and it is only calling the creation method.. so presumably the previously removed circle is still lurking? To test I commented out the creation code and just left the addChildAt() line in, whihc did nothing, as expected. Also tried specifically targeting it with getChildByName() and it returns null, as I expected.

I can't seem to access the 'opacity' property, so I can't see if it's something there (the opacity is hard-coded, shouldn't be altered by other things.

Any ideas are gratefully welcomed. Have a nice Friday

Removing MovieClips And Adding A Win/lose Page?
I am creating a kids game and need to remove a click event listener after you click a character once, until the timer event places the character back on stage again.

For example, you click on a good character and your energy goes up and you click on a bad character and your energy goes down. I don't want you to be able to keep clicking on the same character while they are on stage and make the energy go up and down.

I also need to remove all of the movieclips when the game is over and go to a win or lose screen. Does anyone have some suggestions on the best way to handle this.

Here is the code and a link to the game so you will have an idea of what I am talking about.

Thanks Scott

http://misc.graphxco.net/DDtest/game.html

.fla code

[as]

stop();

var score:int;// lynda.com Tut
var energy:int;// lynda.com Tut

//Code from lynda.com that is placed inside a MovieClip controlling energy..

/*function hurtPlayer(event:MotionEvent):void
{
var main:MovieClip = MovieClip(this.parent.parent);
main.decreaseEnergy();
this.parent.removeChild(this);
}

function die(event:MotionEvent):void
{
var main:MovieClip =MovieClip(this.parent.parent);
main.increaseScore();
this_animator.removeEventListener(MotionEvent.MOTI ON_END, hurtPlayer);
this.parent.removeChild(this);
}*/

//NEED to add text Field to test edu_Tut

/*var hits:int = 0;// tHits NEED to add text Field to test edu_Tut
var shots: int =0;// tshots NEED to add text Field to test edu_Tut
var duckCount = 0;// tDucks NEED to add text Field to test edu_Tut
var score:int = 0;// tScore NEED to convert to a graphic edu_Tut*/

/*var urlShot:URLRequest = new URLRequest("shot.mp3");//Need Sound effect edu_Tut
var sndShot:Sound = new Sound(urlShot);
var urlGotOne:URLRequest = new URLRequest("gotOne.mp3");//Need Sound effect edu_Tut
var sndGotOne:Sound = new Sound(urlGotOne);*/


var duckTimer:Timer = new Timer(3000, 1);
duckTimer.addEventListener(TimerEvent.TIMER, makeADuck);
duckTimer.start();


function makeADuck(evt:TimerEvent):void {
/*duckCount += 1;//extra from edu_Tut
tDucks.text = String(duckCount);//extra from edu_Tut */

var newDuckuck = new Duck();//(10) Point sys tPoints TEXT FEILD add to all Characters replace w/ movieClip
var duckIndex:Number = this.getChildIndex(gdCheet1)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 204.8;
newDuck.swim();
//newDuck.disposition = "good";
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);


//Not Exactly Sure Where to Place This..
/*
score = 0;// lynda.com Tut
energy = energy_mc.totalFrames;//lynda.com Tut
energy_mc.gotoAndStop(energy);// lynda.com Tut*/
}


var duckTimer2:Timer = new Timer(35000,1);
duckTimer2.addEventListener(TimerEvent.TIMER, makeADuck2);
duckTimer2.start();

function makeADuck2(evt:TimerEvent):void {

var newDuckuck2 = new Duck2();
var duckIndex:Number = this.getChildIndex(duck2Fnl)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 178.2;
newDuck.swim();
//newDuck.disposition = "bad";
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);

}

var duckTimer3:Timer = new Timer(20000,1);
duckTimer3.addEventListener(TimerEvent.TIMER, makeADuck3);
duckTimer3.start();

function makeADuck3(evt:TimerEvent):void {

var newDuckuck3 = new Duck3();
var duckIndex:Number = this.getChildIndex(bamboo1)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 98.0;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);


}

var duckTimer4:Timer = new Timer(25000,1);
duckTimer4.addEventListener(TimerEvent.TIMER, makeADuck4);
duckTimer4.start();

function makeADuck4(evt:TimerEvent):void {

var newDuckuck4 = new Duck4();
var duckIndex:Number = this.getChildIndex(goodMnky2)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 147.6;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);

}

var duckTimer5:Timer = new Timer(25000,1);
duckTimer5.addEventListener(TimerEvent.TIMER, makeADuck5);
duckTimer5.start();

function makeADuck5(evt:TimerEvent):void {

var newDuckuck5 = new Duck5();
var duckIndex:Number = this.getChildIndex(goodMnky)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 58.1;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);

}

var duckTimer6:Timer = new Timer(27000,1);
duckTimer6.addEventListener(TimerEvent.TIMER, makeADuck6);
duckTimer6.start();

function makeADuck6(evt:TimerEvent):void {

var newDuckuck6 = new Duck6();
var duckIndex:Number = this.getChildIndex(goodMnky)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 389.6;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);

}



var duckTimer7:Timer = new Timer(15000,1);
duckTimer7.addEventListener(TimerEvent.TIMER, makeADuck7);
duckTimer7.start();

function makeADuck7(evt:TimerEvent):void {

var newDuckuck7 = new Duck7();
var duckIndex:Number = this.getChildIndex(bamboo1)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 374.6;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);

}

var duckTimer8:Timer = new Timer(30000,1);
duckTimer8.addEventListener(TimerEvent.TIMER, makeADuck8);
duckTimer8.start();

function makeADuck8(evt:TimerEvent):void {

var newDuckuck8 = new Duck8();
var duckIndex:Number = this.getChildIndex(bamboo1)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 485.5;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);

}

var duckTimer9:Timer = new Timer(8000,1);
duckTimer9.addEventListener(TimerEvent.TIMER, makeADuck9);
duckTimer9.start();

function makeADuck9(evt:TimerEvent):void {

var newDuckuck9 = new Duck9();
var duckIndex:Number = this.getChildIndex(goodMnky)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 385.4;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);

}

var duckTimer10:Timer = new Timer(25000,1);
duckTimer10.addEventListener(TimerEvent.TIMER, makeADuck10);
duckTimer10.start();

function makeADuck10(evt:TimerEvent):void {

var newDuckuck10 = new Duck10();
var duckIndex:Number = this.getChildIndex(goodMnky)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 352.3;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);


}

// lynda.com Energy Bar "energy_mc"
/*
function increaseScore():void
{
score ++;
if(score >= monsterInGame)
{
monsterMaker.stop();
showWinLose("You Win!");

}
}


function decreaseEnergy():void
{
energy --;
if(energy <=0)
{
monsterMaker.stop();
showWinLose("You Lose!")
}
else
{
energy_mc.gotoAndStop(energy);
}
}


function showWinLose(endMessage:String):void
{
var winLose:MovieClip = new WinLose();
addChild(winLose);
winLose.end_txt.text = endMessage;
}
*/
function clickDuck(evt:MouseEvent):void {
evt.target.hit();
if (evt.target.disposition == "bad") {
smileMeter_mc.prevFrame();
if (smileMeter_mc.currentFrame == 1) {
trace("You Are a Loser");
gotoAndStop("loser");
//duckTimer.removeEventListener(TimerEvent.TIMER, makeADuck);
//stage.removeEventListener(MouseEvent.MOUSE_MOVE,mo veTarget);
//duckTimer.stop();
}

} else {
smileMeter_mc.nextFrame();
if (smileMeter_mc.currentFrame == 20) {
trace("You Are a BadAss Winner");
gotoAndStop("winner");
duckTimer.stop();
}
}
trace("Click Duck!");

/*hits += 1;// Don't Need extra from edu_Tut
tHits.text = String(hits);// Don't Need extra from edu_Tut
score += evt.target.points;// score need to convert to energy_mc edu_Tut
tScore.text = String(score);// score need to convert to energy_mc edu_Tut
sndGotOne.play();// Need sound Effect edu_Tut
*/
}

/*function anyClick(evt:MouseEvent):void
{
shots +=1;
tShots.text = String(shots);
sndShot.play(); //May not need this function. Nee Sound Effect edu_Tut
}


Mouse.hide();
mTarget.mouseEnabled = false;
function moveTarget(evt:MouseEvent):void {
//target graphic = mTarget
mTarget.x = evt.stageX;
mTarget.y = evt.stageY;
}
stage.addEventListener(MouseEvent.MOUSE_MOVE,moveT arget);

[as]

.as external code


[as]

package {

import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.motion.Animator;

public class Duck extends MovieClip {
var duckHit_animator:Animator;
public var disposition:String = "good";
//public var points:int;// form TUT


function Duck():void {
this.disposition = "good";

}
public function swim():void {
var swimTween = new Tween(this, "x",None.easeNone,4.8,4.8, 5, true);

}
public function hit():void {

var duckHit_xml:XML = <Motion duration="11" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="24" x="245.15" y="586.9" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="duckHit">
<dimensions>
<geom:Rectangle left="-85.65" top="-51" width="171.3" height="102"/>
</dimensions>
<transformationPoint>
<geomoint x="0.5046701692936368" y="0.5"/>
</transformationPoint>
</Source>
</source>

<Keyframe index="0" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="0" blurY="0" color="0xFF0000" alpha="1" strength="0" quality="1" inner="false" knockout="false"/>
</filters>
</Keyframe>

<Keyframe index="5" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="56" blurY="56" color="0xFFCC00" alpha="1" strength="1" quality="3" inner="false" knockout="false"/>
</filters>
</Keyframe>

<Keyframe index="10" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="0" blurY="0" color="0xFF0000" alpha="1" strength="0" quality="1" inner="false" knockout="false"/>
</filters>
</Keyframe>
</Motion>;

duckHit_animator = new Animator(duckHit_xml, this);
duckHit_animator.play();



}
}
}

[as]

[advice] Best Practices For Adding/removing Items
Hey, all!

I thought i'd start this thread to uncover peoples habits and practices when it comes to the simple operation of adding and removing elements on stage. I ask because there are so many alternatives, and I keep wondering sometimes what might be the best/most eficcient way of doing it. Let me explain by giving an example:

Your user has chosen to click that flashing button that says "Sign up for our mailing list" and you need to prompt the user for a valid e-mail address by presenting him/her with an alert box on top of everything else. Do you...

a) gotoAndStop("alertbox");

b) alertBox_mc.gotoAndStop("show");

c) this.attachMovie("alertBox_mc", "alertBox_mc", 99)

d) alertBox_mc._x = 200
alertBox_mc._y = 200
(assuming mc was first placed off stage)

e) alertBox_mc._visible = true

f) alertBox_mc._alpha = 100

or

g) this.createEmptyMovieClip("alertBox_mc", 99)
alertBox_mc.createTextField("header", ....
...and so on (create everything is from AS)

...or any other solution you might prefer. Of course, different situations call for different solutions, but which one do you find yourself using the most?

Personaly, option a and c are my weapons of choice, but they come with a few drawbacks. I.e. option a would require you to work with potentially a large number of mc's on stage that in idle state only display as a tiny, white dot (when authoring), and when there are 10 of them on stage they become hard to tell apart and often i find myself clicking 4 or 5 of them before finding the right one.

Please contribute!

Øyvind, Oslo, Norway.

Adding / Removing Stage Event Listeners...
Hello
I need a little help with adding and removing stage event listeners

I am relatively new to AS 3 and have been building a liquid layout site

unfortunately I do not have a strong grasp of classes and have been doing all of my scripting on the main timeline
with encapsulated script within MC's.

basically I am calling on the same functions over and over
and those are mostly resize functions which I have added StageEventListeners
on the appropriate frames to listen for resize events on that stage
now as of now I have literally dozens of these scattered about the site.

when testing my site things are running fairly smoothly
however I keep getting error messages in my output window that go a little something like this.

Code:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at ShawnConveyTestv3_fla::MainTimeline/setPos()
   at ShawnConveyTestv3_fla::MainTimeline/resizeHandler1()


they vary as to which resize handler I have offended at that moment.

but my question is (in 2 parts)

1) what is the best way to add and remove listeners to the stage (cleanest and simplest)

2) assuming you are going to tell me that I will have to learn classes and packages, could anyone point me to a good online reference
for a crash course on these topics? I am sure that my life could be greatly simplified if I understood these key concepts, but for some
reason I have not been able to fully grasp them. ( this coding thing is a bit new to me, I am a visual artist by training)

any help would be greatly greatly appreciated

thanks

her is some sample code of the mess I have scripted myself in....

Code:

import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener (Event.RESIZE, resizeHandler);  //   **  invisible flex back     **
stage.addEventListener (Event.RESIZE, resizeHandler1); //   **  for Navigation / intro  **




// --> Backgrounds for MC's set to invisable <-- //
body1_mc.invis_mc.alpha = 0;
body2_mc.invis_mc.alpha = 0;
body_mc.invis_mc.alpha = 0;
header_mc.invis_mc.alpha = 0;
footer_mc.invis_mc.alpha = 0;
dim_mc.alpha = 0;




// --> Initialize Flex-Sizing & Original Stage positions <-- //
resizeHandler (null);
function resizeHandler (event:Event):void {
  var sw:Number = stage.stageWidth;
  var sh:Number = stage.stageHeight;
  header_mc.height = 30;
  footer_mc.height = 100;
  body1_mc.width = 15;
  body2_mc.width = 15;
  header_mc.x = 0; 
  header_mc.y = 0; 
  body_mc.x = 15; 
  body_mc.y = 30;
  body1_mc.x = 0; 
  body1_mc.y = 30; 
  body2_mc.x = sw-body2_mc.width; 
  body2_mc.y = 30; 
  footer_mc.x = 0; 
  header_mc.width = footer_mc.width = sw;
  body_mc.width = sw-body1_mc.width-body2_mc.width;
  body_mc.height = sh-header_mc.height-footer_mc.height;
  body1_mc.height = sh-header_mc.height-footer_mc.height;
  body2_mc.height = sh-header_mc.height-footer_mc.height;
  footer_mc.y = sh-footer_mc.height;
 
  // --> controls the dim curtain for gallery viewing pleasure <-- //
   dim_mc.x = stage.stageWidth / 2;
   dim_mc.y = stage.stageHeight / 2;
   dim_mc.width = stage.stageWidth;
   dim_mc.height = stage.stageHeight;
   
}

function setPos() {
////////////////////////////////////////////////////////////////////////////////////////////
//   ->  center registration
////////////////////////////////////////////////////////////////////////////////////////////

   preBack.x = stage.stageWidth / 2;
   preBack.y = stage.stageHeight / 2;
   preBack.width = stage.stageWidth;
   preBack.height = stage.stageHeight;
   preBack.scaleX <= preBack.scaleY ? (preBack.scaleX = preBack.scaleY) : (preBack.scaleY = preBack.scaleX);



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//   BL-> Bottom Left registration
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   
   buttons.x=15;
   buttons.y=stage.stageHeight-25;
   
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//   BR  -> bottom Right registration
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   
   br_btn.x=stage.stageWidth-110;
   br_btn.y=stage.stageHeight-25;
   
///////////////////////////////////////////////////////////////////////////////////
//   TR  -> Top Right registration
///////////////////////////////////////////////////////////////////////////////////

   intro2_mc.x=stage.stageWidth-125;
   intro2_mc.y=40;
}
setPos();

function resizeHandler1(event:Event):void {

   setPos();
   //setBackground();
}



///////////////
/// contact ///
//////////////

br_btn.email_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest("mailto:shawn@me.com"),"_self" );
}

buttons.addEventListener(MouseEvent.CLICK, btnClick);
var btnName = "";
function btnClick(event:MouseEvent):void
{
btnName = event.target.name;
   //gotoAndStop(3);
gotoAndStop(btnName);
}
stop();


Code:

stage.addEventListener (Event.RESIZE, resizeHandler2); //   **for SSP gallery #2 (still)**
stage.addEventListener (Event.RESIZE, sSubHandler);

// --> Initialize Flex-Sizing & Original Stage positions   **for SSP gallery #2 (still)**  <-- //
resizeHandler2 (null);
function resizeHandler2 (event:Event):void
{
  ssp1.x = 15;
  ssp1.y = 30;
  ssp1.width = stage.stageWidth-body1_mc.width-body2_mc.width;
  ssp1.height = stage.stageHeight-header_mc.height-footer_mc.height;
  }

  sSubHandler (null);
function sSubHandler (event:Event):void
{
  sSub_mc.x=30;
  sSub_mc.y=stage.stageHeight-50;
}
 
dim_mc.alpha = 0;
dim_mc.addEventListener(Event.ENTER_FRAME, dimmer);

function dimmer(event:Event):void
{
   dim_mc.alpha += .01;
   if(dim_mc.alpha >= .8)
   {
      dim_mc.alpha = .8;
      //dim_mc.removeEventListener(Event.ENTER_FRAME, dimmer);
   }
}

sSub_mc.addEventListener(MouseEvent.CLICK, sSubClick);
var sSubBtnName = "";
function sSubClick(event:MouseEvent):void
{
sSubBtnName = event.target.name;
   //gotoAndStop(3);
gotoAndStop(sSubBtnName);
}


thanks for looking

you can also see the development site at http://www.shawnconvey.com/dev5

Adding/Removing Events From A Single Enter_Frame Loop?
Greetings,

I'm creating another game, this time in AS3. It is my first AS3 project. In my previous games, I developed in pretty much AS1 and just about every movieClip had it's own enterFrame function. I keep hearing about code that uses a single enterFrame function to execute all things needed, but alas I have never attempted such a routine.

I have many ideas on how to achieve it, however I was hoping to get some official examples from people who, well, know more than me! Obviously, I don't want to be all like amateur hour and end up creating a piece of code that ends up more taxing on system resources, slowing performance, more than my old style of executing events!

To be clear, I'm looking to run a single enterFrame event that could have events added and removed from it. So, say you had a moving cannon that shot a single cannon ball. You would have a function for the movement of the cannon, and another function for the movement of the cannon ball. Both of these would be executed on enterFrame. Instead of adding an enterFrame event listener to each sprite, add the functions so that a single enterFrame, running perhaps on the root, would know to execute these functions. Furthermore, when the cannon ball moves off screen, the function would be removed from the single enterFrame.

Any code examples or links to tutorials would be most welcome!
Many thanks!
-sc2071

Adding And Removing Event Listeners On Dynamically Loaded MovieClips?
Hi,

I've created a drop down list and populated it with dynamic buttons. (I made a DropDown_btn class with a dynamic text field in it and then filled the button text from an xml file). On rollover I tint the button blue and then set the tint back to black on rollout. When you click on the button I'd like it to stay blue until a different button is clicked.

I thought on CLICK I'd run a function like this:


ActionScript Code:
function removeRollover(evt:MouseEvent):void {
    evt.target.transform.colorTransform=c;
    evt.target.removeEventListener(MouseEvent.ROLL_OUT, btnOut);
    evt.target.removeEventListener(MouseEvent.ROLL_OVER, btnOver);
}


...and then I need to addEventListeners back to any button that doesn't have them and set that button back to black. I could do this by looping through an array of the buttons but I can't figure out how to access them as objects.

I've made an array of the instance names but don't know how that might help.

I also gave them each a property of "buttonValue" when I loaded them so I can access event.currentTarget.buttonValue (which in this case is a number from 1-5) but once again I can't figure out how I might leverage this information.

I'd appreciate any help you can give.

Thanks

Adding A Mask :confused:
In flash mx i am trying to achieve the effect that my scrollable text box is appearing on the page by scribbling in, like on www.inarms.net ... i know i need to make some sort of a mask, but how do i make a mask that makes only the stuff on that layer transparent? so you can stilll see the background?

thanks in advance...
chris

Adding A Guide Layer To A Mask.
I have a layer with pics.
I have a layer with a symbol, and i turned it into a mask of the pics. I added a motion tween to the mask, and everything works fine.
Now, HOW DO I ADD A GUIDE LAYER to the mask. I'm pretty sure I have doen this before, but for some reason it won't work. If I add the guide layer to the mask, it unmasks the pics. WHY WHY WHY???
The worst part? I only have about 1 hour to get this to work, HELP PLEASE!!!

Adding Mask Makes Movieclip Disappear
Maybe someone can shed light on a bizarre problem.

I have 2 stripped-down examples of MX 2004 Flash files that
have a pair of movie-clips, an outer one and an inner one.
The outer-clip sets up a layer mask over the inner one, and
as soon as it does, the entire inner-clip disappears.

I have 2 FLA versions of it in an attached ZIP. One works
and one doesn't. Both use gotoAndStop slightly differently
to set up a particular frame in the inner-clip.

To illustrate the problem, the outer clip contains some
shapes (in red) as well as containing the inner clip (in blue).
The working version clips both shapes and clip properly.
The failing version clips the shapes but makes the inner-clip
disappear.

It's very odd: the entire inner-clip disappears as soon as the
mask is loaded.

Adding Listeners And Removing Listeners
Hi all,

I've come across a problem during the creation of a flash movie..

Basically the movie consists of two scenes. Key.LEFT moves from "help" scene to "interface" scene and numpad 9 goes to "help" from "interface".

It works fine from "help" to "interface" the Key.removelistener(helpListener) disables the Key.LEFT. But on going back to the "help" scene the Key.removeListener(interListener) doesn't disable numpad 9 enabling the user to jump to and from each scene with each press (code at bottom).

Is this usual behaviour? Does it have anything to do with help being the first scene and trying to remove something that hasn't been created yet?

Any work arounds or solutions to this problem would be greatly appreciated!!

Thanks in advance,

Ben Gazzard

Each scene;
----------------------------------------------------------------------
Help:

Key.removeListener(interListener);
helpListener = new Object();
helpListener.onKeyDown = function() {
if (key.LEFT) {
gotoAndPlay("Scene 1", 1);
}
};
Key.addListener(helpListener);
stop();

----------------------------------------------------------------------
Interface:

Key.removeListener(helpListener);
interListener = new Object();
interListener.onKeyDown = function() {
if (key.isdown(105)) {
gotoAndPlay("help", 1);
}
};
Key.addListener(interListener);
stop();

Removing Attached Movie And Resetting/removing All The Variables It Set?
I have attachMovie() that calls up an item with a Class that extends movie clip, it gets refresh but it is not removing the variables it set earlier and it's giving me a headache.

Is there a way to remove it and ALL the variables contained within?

Thanks!

AS3: Mask Within A Mask (or How To Use A Shape With A Hole In It As A Mask)
Hi guys,

I've been stuck on this AS 3 masking problem for days now. I'm sure there's a simple solution to my problem but it's proving to be a pain.

I have a movieclip that contains some drawings, bitmap, etc. on top of that I am drawing a yellow rectangle with a hole in it using ActionScript:




What I want to achieve is to mask the movieclip container using the yellow rectangle, but I want the hole in the middle to not show the drawings and line:




However what I am actually getting is the yellow rectangle is masking the movieclip, but is ignoring the hole within it:




This is the AS3 code that I've written to get the above effect (with 'maskee' being the movieclip that contains the drawings):


Code:
function drawRectMask(p_sprite:Sprite) : void {
p_sprite.graphics.beginFill(0xf0ff00);
p_sprite.graphics.drawRect(100,100,300, 300);
p_sprite.graphics.moveTo(100,200);
p_sprite.graphics.drawRect(150,150,100, 100);
p_sprite.graphics.endFill();
}

var spr:Sprite = new Sprite();
drawRectMask(spr);
addChild(spr);

maskee.mask = spr ;

I'm at wits end. Any help on this would be greatly appreciated.

Client Request Feathered Mask Or Soften Fill Edges Mask
What application do you use to mock up flash designs?Photoshop7

How To Mask Duplicated Movie Clips With A Single Mask?
I have created 11 movie clips 17px in a vertical column.

I have used this code to duplicate them.


ActionScript Code:
for(i=0; i <10; i++){
    newName = "softwareBar" + i;
    duplicateMovieClip("softwareBar", newName, i);
    softwareBar._y += 17;
}

I have a mask that I need to use to cover all the clips, however when I use setmask it only covers the last looped item in the duplicateMovieClip code.

How would I go about masking all the duplicated clips with a single mask?


Not sure if this info is pertinent but once they are masked I will then be animating each duplicated bar separate using this function.


ActionScript Code:
loadBar = function(clipName, amount){
    clipName.onEnterFrame = function(){
        if(clipName._width<amount){
            clipName._width +=speed * speedDim;
        }
    }
}

Thanks
DDC

Mask Over Mask Leaving Pasrts Covered From Overlap.
Hello,

I have a complex image that I would like to mask with an animated mask.

I am using a movie clip with a couple of layers that "reveal" parts of the complex image at a time.
The problem is, when part of a mask overlaps another, it leaves that part of the complex image covered.

Is there a way around this?

Thanks in advance.

Drag A Mask, With Out Draging The MC Under That I Want To Mask Over?
Hello,

I have a mask and MC button which I am draging. I works fine other the fact the the whole MC movies even the MC inwhich I want to mask over: "BigYears" .

I have tryed to use:
onClipEvent (enterFrame) {
setProperty (this.BigYears, _x, -this._x);
setProperty (this.BigYears, _y, -this._y);
}

Then "BigYears" is not viewable under the mask.

INVERSED Mask? REVERSE Mask?
Okay, here's my dilemma.

I want a small circle to grow to reveal the contents within the circle, and THEN (and this is the hard part) I want another circle to grow from the same starting point that makes shows THROUGH to what's behind the circle.

So

I already have the first part done, where there's the contents on one layer, and a masked circle that tweens to reveal the contents.

BUT, the second part has to reveal the INVERSE of the contents... I don't really know HOW to explain this other than saying I want to punch a hole THROUGH the contents.

Any ideas?

HELP I Need A Mask Guru To Help Me With A Mask Problem
Hi,

I've got two mc's that are suppose to be playing simultaneously. Both duplicate mc's are called "Cloud Motion Tween" and there is one on the main timeline that has a brightness of -55 and the other duplicate of that mc is inside a mask in a mc called "Nav Bar (About)". Both mc's are suppose to be in sync.

Now every time I rollover the "Nav Hit Panel" button the mc inside the mask starts all over again and stuffs up the synchronization of the two mc's.

I have attached the fla file. You'll see what I mean.

Thank you so much for you valued time and effort. You are a true champ!!! (Whoever you are)

Blastbum

HELP I Need A Mask Guru To Help Me With A Mask Problem
Hi,

I've got two mc's that are suppose to be playing simultaneously. Both duplicate mc's are called "Cloud Motion Tween" and there is one on the main timeline that has a brightness of -55 and the other duplicate of that mc is inside a mask in a mc called "Nav Bar (About)". Both mc's are suppose to be in sync.

Now every time I rollover the "Nav Hit Panel" button the mc inside the mask starts all over again and stuffs up the synchronization of the two mc's.

I have attached the fla file. You'll see what I mean.

Thank you so much for you valued time and effort. You are a true champ!!! (Whoever you are)

Blastbum

Copyright © 2005-08 www.BigResource.com, All rights reserved