Add And Removing Child From Within A Function Problem
I have the following function:function textnumber(event:MouseEvent):void { //if any phone number fields are not filled if (area_code.length != 3 || phone_3.length != 3 || phone_4.length!= 4){ tb_number.addChild(bad_number); } //if phone number fields are correct else{ tb_number.removeChild(bad_number); }}The child is ADDED fine, but when the phone number fields are correct and the function executes, it should remove the "bad_number" child. It doesn't though, I'm wondering how within that function I can target the bad_number child to get rid of it?
KirupaForum > Flash > ActionScript 3.0
Posted on: 08-28-2008, 03:17 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Stop FLV Playback In Child When Removing Child (or At Least Silence Audio)
I'm working on a flash site with a number of different "states" (home, features, demo, etc.) each of which is a movie clip with its own actionscript, added as a child when requested, removed when the user chooses a new state.
One of the states plays short FLV videos. The problem is, when switching away from that state to a different state, even though the child is removed, the current video apparently keeps playing as I can hear the audio continuing on.
To demonstrate, the site is here. Click on "Demo", then play one of the videos and switch to a different state (home, features, whatever) while the video plays.
I'm trying to call a function in the child to stop video playback (first checking whether the function exists before trying to call it). The checking part works, but the function call is giving me a "call to possibly undefined method" error when publishing. Probably because I'm calling it the wrong way.
Here's the "remove child" code used after switching to a new state:
Code:
var child:DisplayObject;
while(stateContainer.numChildren > 1)
{
child = stateContainer.getChildAt(0);
if ('stopPlayback' in child)
{
trace('exists');
child.stopPlayback();
}
else
{
trace('does not exist');
}
stateContainer.removeChildAt(0);
}
Can you tell me a better way to do this? I find it strange that it traces "exists" when the function exists, but still complains that child.stopPlayback() (might not) exist.
Removing A Child Inside A Child
I have a main swf file that loads and external swf file which loads an additional external swf file. I am using the addChild method to load these swf files. I am able to get the first child to unload using
function goMain(event:MouseEvent):void
{
this.parent.parent.removeChild(this.parent);
}
but I am having trouble getting the child swf inside of the first child swf to unload. Does any one know how to solve this problem. I tried
function goMain(event:MouseEvent):void
{
this.parent.parent.parent.parent.removeChild(this. parent);
}
but it does not work.
Variables Of A Child Not Visible To A Function In The Child Called From Its Parent ?
sorry, this is a repeat thread, but couldn't change the title on the old one, someone must know the solution to this problem, I just dont think i worded it correctly enough for someone who knew what i was talking about to notice last time.
Ive got a movieclip that creates and adds a child mc then calls a function in the new mc. the function runs, but the local vars for the new mc aren't visible to the function. Is there a special way to call a function so that its scope is in the child, not in the parent ? ( i assume thats where it is, even though a trace of this returns the correct object type )
ie:
[Parent Clip]
--[child clip: movGraph]
--variable ( var thegraph:MovieClip = this; )
--[function loadMe]
--(trace (theGraph); )
calling movGraph.loadMe spits out undefined or null object error, as opposed to
[object movGraph]
obviously i want to do a whole lot more than trace out the object type, and trace(this) in the function returns [object movGraph]. the variable "theGraph" declared in the child isn't available or its null somehow.
Can anyone tell me where I'm going wrong ? - any help would be appreciated. at the moment I'm having to add all the code in the function instead of the "root" of the child. which really defeats the point.
Removing A Child
Hello, Maybe it was asked before, I searched but find anything.
It is simple, I have this code in Flash:
var rain:Sprite = new Sprite();
addChild(rain);
stage.addEventListener(MouseEvent.CLICK, raining);
function raining(event:MouseEvent):void {
var drop:Water = new Water();// from my library
drop.x = Math.random ()*stage.stageWidth;
drop.y = -Math.random()*25;
rain.addChild(drop);}
In the mc with the class name "Water", I made an animation and at the end of it, I want to remove the instance, so I wrote :
parent.removeChild(this) // parent is the sprite "rain"
It works but it gives me this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at Water/::frame4()[Water::frame4:3]
Thanks for your help
[AS3] Help With Removing All Child
Hi there...
I just need help with my Clip class here...my attempt is attaching some mc's problem the library call "Clip" from mouse click and delete all the attach Clip within 2 seconds after randomly movement...I manage to get attach the Clip and move it as suppose to but have no idea how to eliminate all the Clip from the stage..being struggling here but not to avail..
my fla..mc in library call "Clip"
Code:
stop();
var obj:Clip = new Clip();
stage.addEventListener(MouseEvent.MOUSE_DOWN, startAddClip);
function startAddClip(e:Event):void{
obj.addClip(this,this.mouseX,this.mouseY);
}
and here are the Clip class file
Clip.as
Code:
package{
import flash.display.*;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Clip extends Sprite{
private var holdSec:Timer;
private var clip:Clip;
private var total:Number =50;
private var mcArr:Array = new Array();
private var _stage:DisplayObjectContainer;
public function Clip(){
}
public function addClip(stage_:DisplayObjectContainer,xcoor:Number,ycoor:Number):void{
var len:Number;
_stage = stage_;
for(var i:Number=0;i<total;i++){
clip = new Clip();
clip.x = xcoor;
clip.y = ycoor;
_stage.addChild(clip);
mcArr.push(clip);
}
len = mcArr.length;
for(var j:Number=0;j<len;j++){
mcArr[j].addEventListener(Event.ENTER_FRAME, goChaos);
}
}
private function goChaos(e:Event):void{
e.currentTarget.x += randRange();
e.currentTarget.y += randRange();
e.currentTarget.alpha = Math.random()*.5+.02;
holdSec = new Timer(2000);
holdSec.addEventListener(TimerEvent.TIMER, removeClip);
holdSec.start();
}
private function randRange():Number{
return Math.random()*10-5;
}
private function removeClip(e:TimerEvent):void{
holdSec.removeEventListener(TimerEvent.TIMER, removeClip);
e.currentTarget.stop();
//_stage.removeChild(clip);----->HOW TO REMOVE ALL CLIP
mcArr.splice(0);
trace(mcArr.length);
}
}
}
Any help are really appreciated...at least give me some shed of light or point me my mistake..TQ in advanced
Removing A Child From Within Itself...
Alright, so i am doing soem work in flashdevelop and im encountering a small problem when i try to remove a movieclip from within itself.
MainChar class
PHP Code:
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.KeyboardEvent; public class MainChar extends Body { public function MainChar() { this.addEventListener(Event.ADDED_TO_STAGE, staging); } private function staging(e:Event):void { stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown); } private function handleKeyDown(e:KeyboardEvent):void { switch(e.keyCode) { case 90 : addChild(new Anim(this)); break; } } } }
PHP Code:
package { import flash.display.MovieClip; import flash.display.Sprite; /** * ... * @author DefaultUser (Tools -> Custom Arguments...) */ public class Body extends MovieClip { public var Name:String; public var body:Sprite = new Sprite(); public function Body() { body.graphics.beginFill(Math.random()*0xffffff); body.graphics.drawCircle(0, 0, 10); body.graphics.endFill(); addChild(body); } } }
this is what gets added from the MainChar class:
PHP Code:
package { import flash.display.MovieClip; import flash.events.Event; /** * ... * @author DefaultUser (Tools -> Custom Arguments...) */ [Embed (source = "library.swf", symbol = "Swing")] public class Anim extends MovieClip { private var remover:MovieClip; public function Anim(cest:MovieClip) { remover = cest; addEventListener(Event.ENTER_FRAME, init); } private function init(e:Event):void { if (currentFrame == totalFrames) { remover.removeChild(this); } } } }
its throwing that null object reference error...:
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Removing Child Error
Hi, having trouble removing web page content, when I click on the navigation buttons the previous page content ( brought in dynamically by actionscript 3 ) remains and the current page content is displayed on top of it . Trying to use boolean variables and conditionals to remove the unwanted content but keep getting these errors:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at francis_fla::MainTimeline/checkContent()
at francis_fla::MainTimeline/clickHome()
TypeError: Error #2007: Parameter child must be non-null.
at flash.display:isplayObjectContainer/removeChild()
at francis_fla::MainTimeline/checkContent()
at francis_fla::MainTimeline/clickGallery()
Here's my code, any help appreciated:
stop()
// ---------------- navigation buttons code ---------------------
var homeContent:Boolean = true; // starts off true because it loads automatically on arrival at web page
var galleryContent:Boolean = false;
var contactContent:Boolean = false;
var linksContent:Boolean = false;
// add event listeners to each navigation button to send viewer to the named label frame when the button is clicked on using gotoAndStop
Home.addEventListener(MouseEvent.CLICK, clickHome);
function clickHome(event:Event):void {
homeContent = true;
trace ("home");
gotoAndStop("Home");
checkContent();
}
Gallery.addEventListener(MouseEvent.CLICK, clickGallery);
function clickGallery(event:Event):void {
galleryContent = true;
trace ("gallery");
gotoAndStop("Gallery");
checkContent();
}
Contact.addEventListener(MouseEvent.CLICK, clickContact);
function clickContact(event:Event):void {
contactContent = true;
trace ("contact");
gotoAndStop("Contact");
checkContent();
}
Links.addEventListener(MouseEvent.CLICK, clickLinks);
function clickLinks(event:Event):void {
linksContent = true;
trace ("links");
gotoAndStop("Links");
checkContent();
}
function checkContent():void {
if(homeContent = true){
removeChild(homeTextField_txt);
}
if(galleryContent = true){
removeChild(galleryLoader);
}
else if(contactContent = true){
removeChild(contactTextField_txt);
}
else if(linksContent = true){
removeChild(linksTextField_txt);
}
}
Removing A Child Object
I have a web site that creates a page by calling another class object. When I return from that page to the Main page I want the old page removed. I have done it like this but I am getting errors.
Two vars in GlobalVarsContainer:
public static var removePages:Boolean;
public static var pageToRemove:Object;
Create new page object:
function onClickBtn1():void
{
var servicesHome:ServicesHome=new ServicesHome();
addChild(servicesHome);
}
Return from sub page:
function onMotionFinish(event:Event):void
{
GlobalVarContainer.removePages=true;
GlobalVarContainer.pageToRemove=servicesHome;
var displayBtns=new ButtonHandler(introVid);
addChild(displayBtns);
}
Function on returning page to remove old object:
//removes a sub page
if (GlobalVarContainer.removePages==true)
{
removeChild(GlobalVarContainer.pageToRemove);
}
This is the error:
ReferenceError: Error #1065: Variable servicesHome is not defined.
So I know it's getting back here with all vars set correctly. I’ve tried changing the public static var pageToRemove:Object; to a string but that is not right.
Any help please, I would greatly appreciate.
Error When Removing Child.
Hi guys. I am new here and thought I'd introduce myself with a problem
I get this error
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at shot/eFrame()
From this code.
Code:
private function eFrame(event:Event):void{
this.x += 6
if (this.x > 240) {
this.parent.removeChild(this);
this.removeEventListener(Event.ENTER_FRAME, eFrame)
}
It is an enter from function on a class called shot. It kills itself when it gets off the screen. Now the error doesn't occur for every shot. It seems to be random which ones actually get the error. I don't know what the problem is.
Hittest An Array And Removing A Child
Ok in my asteroids game when the ship hits a rock I want the ship to be removed and it to go to frame 3 but I cant get it to work.
here is the code I am using
PHP Code:
stop();
//create an array to hold all the rocks
var rockArray:Array = new Array();
//var startTime:int = int(timer);
var rockTimeGap:int = 5;
var timeElapsed:int = 0;
var i:int;
//create the ship and add to the stage
var newShip:Ship = new Ship();
addChild(newShip);
//places the ship in the middle of the stage
newShip.x = stage.stageWidth/2;
newShip.y = stage.stageHeight/2;
//create a rock and add it to the stage
var newRock:Rock = new Rock();
addChild(newRock);
//place it at a random x and y position
newRock.x = Math.random() * stage.stageWidth;
newRock.y = Math.random() * stage.stageHeight;
//make the rocks x and y scale random
newRock.scaleX = Math.random();
newRock.scaleY = Math.random();
// make the x and y direction and speed of the rock a random number between -5 and 5
newRock.xDirection = Math.random()*10-5;
newRock.yDirection = Math.random()*10-5;
// make the direction and speed of the rock random number between -10 and 10
newRock.rotationDirection = Math.random()*20-10;
//add a new rock to the end of the array
rockArray.push(newRock);
//event listener for the keyboard that allows a key to be pressed down
stage.addEventListener(KeyboardEvent.KEY_DOWN,moveShip);
function moveShip(event:KeyboardEvent):void {
//when an arrow key is down then the Ship will move
if (event.keyCode==(Keyboard.RIGHT)) {
newShip.rotation += 15;
trace(newShip.rotation);
} else
if (event.keyCode==(Keyboard.LEFT)) {
newShip.rotation -= 15;
trace(newShip.rotation);
} else
if (event.keyCode==(Keyboard.UP)) {
newShip.y -= 5;
} else
if (event.keyCode==(Keyboard.DOWN)) {
newShip.y += 5;
}
//if ship moves off bottom of the stage then place it at top of the stage
if (newShip.y >= stage.stageHeight) {
newShip.y = 0;
//else if the ship moves off top of the stage then place it at bottom of the stage
} else
if (newShip.y <= 0){
newShip.y=stage.stageHeight;
//else if the ship moves off Right side of the stage then place it at left side of the stage
} else
if (newShip.x >= stage.stageWidth) {
newShip.x = 0;
//else if the ship moves off lef side of the stage then place it at right side of the stage
} else
if (newShip.x <= 0) {
newShip.x=stage.stageWidth;
}
}
//create a timer for the rocks that will fire every 5 seconds
var rockTimer:Timer = new Timer(5000);
//create a timer that will fire every seconds
var timer:Timer = new Timer(1000);
//event listener for the rock Timer and Timer
rockTimer.addEventListener(TimerEvent.TIMER, onTimer);
timer.addEventListener(TimerEvent.TIMER, timedFunction);
//start the rock timer and the timer
rockTimer.start();
timer.start();
function timedFunction(eventArgs:TimerEvent)
{
//display the score in the timer textbox
score_txt.text =(" Score: "+( timer.currentCount + 1));
}
//create a rock when the rock Timer fires and add it to the stage
function onTimer(evt:TimerEvent):void{
var newRock:Rock = new Rock();
addChild(newRock);
//place it at a random x and y position
newRock.x = Math.random() * stage.stageWidth;
newRock.y = Math.random() * stage.stageHeight;
//make the rock scale random
newRock.scaleX = Math.random();
newRock.scaleY = Math.random();
// make the x and y direction and speed of the rock a random number between -5 and 5
newRock.xDirection = Math.random()*10-5;
newRock.yDirection = Math.random()*10-5;
// make the direction and speed of the rock random number between -10 and 10
newRock.rotationDirection = Math.random()*20-10;
//add a new rock to the end of the array and add to the rock count
rockArray.push(newRock);
}
rockArray[i].addEventListener(Event.ENTER_FRAME,handlerocks);
function handlerocks(event:Event):void {
for (var i:int = 0; i< rockArray.length; i++) {
rockArray[i].x += rockArray[i].xDirection;
rockArray[i].y += rockArray[i].yDirection;
rockArray[i].rotation += rockArray[i].rotationDirection;
if (newShip.hitTestObject(rockArray[i])) {
rockTimer.removeEventListener(TimerEvent.TIMER, onTimer);
rockArray[i].removeEventListener(Event.ENTER_FRAME,handlerocks);
stage.removeEventListener(KeyboardEvent.KEY_DOWN,moveShip);
removeChild(newShip);
gotoAndStop("3");
}
if (rockArray[i].y >= stage.stageHeight) {
rockArray[i].y = 0;
} else if (rockArray[i].y <= 0) {
rockArray[i].y=stage.stageHeight;
} else if (rockArray[i].x >= stage.stageWidth) {
rockArray[i].x = 0;
} else if (rockArray[i].x <= 0) {
rockArray[i].x=stage.stageWidth;
}
}
}
Also here is the fla files. The Flash asteroids game fla file is my game and the The Roid_start file is a flie I was given as a starting point. I then had to take that Roid_star file and add in more code to make it into a asteroids game.
Removing MovieClip Child Dynamically
Hi All,
Please help me out in solving this. I have been trying to remove all CHilds in a Movie CLip since Yesterday without success. Movie Clip is being filled dynamically and i also need to remove its child dynamically.
tempSub is a MovieCLip created inside code;
function removeSub(){
for(var i=0; i<tempSub.numChildren; i++){
tempSub.removeChildAt(i);
}
trace("CURRENT : TEMP SUB STATUS")
for(i =0; i<tempSub.numChildren; i++)
{
trace("NUM CHILDREN ARE" + tempSub.numChildren);
trace("CHILD " + i + " is" + tempSub.getChildAt(i));
}
}
So whenever this function is called after the first FOR loop it still shows some value for the numchildren and its child also.
Please tell me why is it not deleting.
Thank You Very Much.
Removing A Child AND Deleting The Reference
In relation to the following post "removing a child", I have a question about cleaning up resources.
From what I've been able to learn, Flash 9 will do an automatic garbage collect when it's ready. So if I'm adding hundreds of particles to the stage, then removing them (and not reusing them) does Flash just clean them when a certain memory usage is reached?
I'm not actually creating any hard references to the clips anywhere (such as event or mouse listeners) only a local variable within the loop that first creates the particles, so I assume that they're marked for deletion?
Is this correct, or do I need to do a this = undefined / null (which didn't appear to work for me anyway)?
Cheers,
Dave
Removing All Children And Then Loading Swf Via Add Child
All of the sites I created in the past use the loadMovieNum(0); to load external swf files into the player. The new swf replaces the old one which is much cleaner than navigating to a new html page.
I understand how to do the same via add child in 3.0. But, every image, button, etc.. in the site, which is designed visually in flash CS3, becomes a child of the parent. So, having code that would remove each child individually would be crazy.
I figured out how to unload all the children with a simple code here...
while (stage.numChildren > 0) {
stage.removeChildAt(stage.numChildren-1);
// When the last child is removed, stage is set to null, so quit
if (stage == null) {
break;
However, using it in the following context, in which an swf called ambiance would load and replace the old one, there are no errors reported, but the new swf doesn't display. I just get a blank swf when I click the button. So, it obviously removes the all the children from the stage, but the new swf isn't loading. Any ideas on how to make it load, or what I am missing ere?
//Ambiance Button
ambiance_btn.addEventListener(MouseEvent.CLICK, ambianceClick);
function ambianceClick(event:MouseEvent):void
{
while (stage.numChildren > 0) {
stage.removeChildAt(stage.numChildren-1);
// When the last child is removed, stage is set to null, so quit
if (stage == null) {
break;
var loader:Loader = new Loader();
loader.load(new URLRequest("ambiance.swf"));
addChild(loader);
}
}
}
Thanks in advance if anyone does... I have been trying this for days on end and am pretty much crazy by now.
Best,
Charles
Removing Child Keeps Playing In The Background
I'm just wondering what is going on with this basic removeChild function using and how it works. Basically I have a main flash interface with swfs getting added inside movie clips as "children" to display each section of my flash application. I have an intro movie that is loaded up in the same way.
But what I notice is even after removing the child when the user clicks another section and re-adding it again when the user clicks "intro" it seems to keep playing in the background causing the rest of the user interface to become a little slow and laggy at times. It is a 9mb flash file (JPEGS!) but I can tell its definitely getting removed I was just expecting it to "Pause" while its not there or stop and then start from the beginning when I re-add the child. (But it seems to carry on looping in the background)
Does anyone know how this works exactly or know any tips to let me user interface run a little smoother by removing children completely?
[as3] DisplayObject Removing Child From List
I have a MovieClip I've added to a DisplayObject via myParent.addChild( foo ), but the child is not disappearing when I call myParent.removeChild( foo ).
How do you recommend I debug this to detemine why the child is removed?
And how do I enumerate all the children off of an existing DisplayObject?
Removing A Child From A Backend Class
Hello,
I have noticed with ActionScript 3 that it is a little hard to work directly with the stage in Classes other than the main document class. stage is not global. I have gotten around this so far by passing the stage as an argument to any other classes in their constructors. However I have found that some DisplayObjectContainer methods will not work when using the stage reference. In particular 'removeChild()'. addChild() works fine. Here is an example using two classes a document class and a backend class:
Main.as (document class)
actionscript Code:
Original
- actionscript Code
package
{
import flash.display.*;
public class Main extends Sprite
{
var circle:Circle = new Circle();
//Circle is a simple circle which has been drawn in the Flash authoring tool and exported as actionscript in the Library panel
public function Main()
{
addChild(circle);
Backend.removeChildFromBackEnd(stage,circle);
}
}
}
package{ import flash.display.*; public class Main extends Sprite { var circle:Circle = new Circle(); //Circle is a simple circle which has been drawn in the Flash authoring tool and exported as actionscript in the Library panel public function Main() { addChild(circle); Backend.removeChildFromBackEnd(stage,circle); } }}
Backend.as
actionscript Code:
Original
- actionscript Code
package
{
import flash.display.*
public class Backend
{
public static function removeChildFromBackEnd(stageObject:Stage,objectToRemove:DisplayObject):void
{
stageObject.removeChild(objectToRemove);
}
}
}
package{ import flash.display.* public class Backend { public static function removeChildFromBackEnd(stageObject:Stage,objectToRemove:DisplayObject):void { stageObject.removeChild(objectToRemove); } }}
This does not work 'removeChild()' throws an ArgumentError. Like I said other methods such as 'addChild()' would have worked fine if they referenced stageObject and were called from the Backend class. Can anyone explain why this isn't working and/or can come up with a workaraound.
Cheers
Ben
Removing Child After GetChildAt, Stuck On How To Implement
I have a class that controls a button, so when the button is clicked it moves the timeline to the next frame. I want it to also remove the child that was added on the frame that the button was clicked on. The problem I have is that I don't know what path to input so that getChildAt will get the right child, and then I don't know how to use what it returns to removeChild using getChildByName which uses what getChildAt returned.
The bold portions are what I don't know what to place in. I am including what I think is the relevant code.
timeline code:
Code:
import lesson.SoundMain;
var sndEx1:SoundMain = new SoundMain("micRec1.mp3");
addChild(sndEx1);
trace(sndEx1);//returns [object SoundMain]
a function in button class to move timeline one frame forward:
Code:
private function oneFrameForward(evt:MouseEvent):void
{
whatGoesHere?.getChildAt(MovieClip(parent).currentFrame);
whatGoesHere?.removeChild(getChildByName("how do I input what getChildAt returned?"));
MovieClip(parent).nextFrame();
}
I am clueless when it comes to what the path is to access objects.
Also, can I just place the whole getChildAt line into the getChildByName parenthesis?
Removing Child From Stage Error #2025
I'm making the transition from AS2 to AS3 and I thought I had began to start thinking in the new way but now I'm stuck again.
I have a click event listener activated by clicking a movieclip. Everything works well, external swfs are loading, alpha changes working on the other movieclip buttons but as soon as I add a script to remove a child(movieclips from the other movieclip buttons) it gives me this error:
[color="black"][color="black"]
WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at mainmovie_fla::MainTimeline/Missionbtn()
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at mainmovie_fla::MainTimeline/collectionClick()
Here is my script, the 2 buttons in question are Collection button and Mission Button
ActionScript Code:
var i=new Loader();
addChild(i);
i.load(new URLRequest("flashslideshow.swf"));
i.x=15
i.y=170
var imageRequest:URLRequest = new URLRequest("about.swf");
var imageLoader:Loader = new Loader();
imageLoader.load(imageRequest);
var collectionRequest:URLRequest = new URLRequest("collection.swf");
var collectionLoader:Loader = new Loader();
collectionLoader.load(collectionRequest)
//LINKS
var blogLink:URLRequest = new URLRequest("http://www.adobe.com");
var storeLink:URLRequest = new URLRequest("http://www.ehecalt.bigcartel.com");
//
//BLOG BUTTON ************************************
blog_mc.addEventListener(MouseEvent.CLICK, Blogbtn);
function Blogbtn(event:MouseEvent):void
{
navigateToURL(blogLink);
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha = 1;
collection_mc.alpha = .4;
}
//
//STORE BUTTON ********************************
store_mc.addEventListener(MouseEvent.CLICK, Storebtn);
store_mc.addEventListener(MouseEvent.ROLL_OVER, StoreOver);
store_mc.addEventListener(MouseEvent.ROLL_OUT, StoreOut);
function StoreOver(event:MouseEvent):void
{
store_mc.gotoAndPlay(2);
}
function StoreOut(event:MouseEvent):void
{
store_mc.gotoAndPlay(5);
}
function Storebtn(event:MouseEvent):void
{
navigateToURL(storeLink);
mission_mc.alpha = .4;
store_mc.alpha = 1;
contact_mc.alpha = .4;
blog_mc.alpha =.4;
collection_mc.alpha = .4;
}
//
// COLLECTION BUTTON
collection_mc.addEventListener(MouseEvent.CLICK, collectionClick);
function collectionClick(event:MouseEvent):void
{
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha =.4;
collection_mc.alpha = 1;
addChild(collectionLoader);
collectionLoader.x = 15;
collectionLoader.y = 170;
removeChild(i);
}
//
//Contact BUTTON ************************************
contact_mc.addEventListener(MouseEvent.CLICK, Contactbtn);
function Contactbtn(event:MouseEvent):void
{
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = 1;
blog_mc.alpha = .4;
collection_mc.alpha = .4;
}
//
//MISSION BUTTON
mission_mc.addEventListener(MouseEvent.CLICK,Missionbtn);
function Missionbtn(event:MouseEvent):void
{
mission_mc.alpha = 1;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha = .4;
collection_mc.alpha = .4;
addChild(imageLoader);
imageLoader.x = 15;
imageLoader.y = 170;
removeChild(i);
}
//buttonmode
contact_mc.buttonMode = true;
blog_mc.buttonMode = true;
store_mc.buttonMode = true;
collection_mc.buttonMode = true;
Removing Child From Stage Error #2025
I'm making the transition from AS2 to AS3 and I thought I had began to start thinking in the new way but now I'm stuck again.
I have a click event listener activated by clicking a movieclip. Everything works well, external swfs are loading, alpha changes working on the other movieclip buttons but as soon as I add a script to remove a child(movieclips from the other movieclip buttons) it gives me this error:
[color="black"][color="black"]
WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at mainmovie_fla::MainTimeline/Missionbtn()
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at mainmovie_fla::MainTimeline/collectionClick()
Here is my script, the 2 buttons in question are Collection button and Mission Button
ActionScript Code:
var i=new Loader();
addChild(i);
i.load(new URLRequest("flashslideshow.swf"));
i.x=15
i.y=170
var imageRequest:URLRequest = new URLRequest("about.swf");
var imageLoader:Loader = new Loader();
imageLoader.load(imageRequest);
var collectionRequest:URLRequest = new URLRequest("collection.swf");
var collectionLoader:Loader = new Loader();
collectionLoader.load(collectionRequest)
//LINKS
var blogLink:URLRequest = new URLRequest("http://www.adobe.com");
var storeLink:URLRequest = new URLRequest("http://www.ehecalt.bigcartel.com");
//
//BLOG BUTTON ************************************
blog_mc.addEventListener(MouseEvent.CLICK, Blogbtn);
function Blogbtn(event:MouseEvent):void
{
navigateToURL(blogLink);
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha = 1;
collection_mc.alpha = .4;
}
//
//STORE BUTTON ********************************
store_mc.addEventListener(MouseEvent.CLICK, Storebtn);
store_mc.addEventListener(MouseEvent.ROLL_OVER, StoreOver);
store_mc.addEventListener(MouseEvent.ROLL_OUT, StoreOut);
function StoreOver(event:MouseEvent):void
{
store_mc.gotoAndPlay(2);
}
function StoreOut(event:MouseEvent):void
{
store_mc.gotoAndPlay(5);
}
function Storebtn(event:MouseEvent):void
{
navigateToURL(storeLink);
mission_mc.alpha = .4;
store_mc.alpha = 1;
contact_mc.alpha = .4;
blog_mc.alpha =.4;
collection_mc.alpha = .4;
}
//
// COLLECTION BUTTON
collection_mc.addEventListener(MouseEvent.CLICK, collectionClick);
function collectionClick(event:MouseEvent):void
{
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha =.4;
collection_mc.alpha = 1;
addChild(collectionLoader);
collectionLoader.x = 15;
collectionLoader.y = 170;
removeChild(i);
}
//
//Contact BUTTON ************************************
contact_mc.addEventListener(MouseEvent.CLICK, Contactbtn);
function Contactbtn(event:MouseEvent):void
{
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = 1;
blog_mc.alpha = .4;
collection_mc.alpha = .4;
}
//
//MISSION BUTTON
mission_mc.addEventListener(MouseEvent.CLICK,Missionbtn);
function Missionbtn(event:MouseEvent):void
{
mission_mc.alpha = 1;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha = .4;
collection_mc.alpha = .4;
addChild(imageLoader);
imageLoader.x = 15;
imageLoader.y = 170;
removeChild(i);
}
//buttonmode
contact_mc.buttonMode = true;
blog_mc.buttonMode = true;
store_mc.buttonMode = true;
collection_mc.buttonMode = true;
If someone could help me get to the bottom of this and help me understand where I went wrong I'd be extremely grateful.
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
Problem Removing Child/wrong Clip Loads
OK, I'm getting a bizarre bug that I can't seem to find a solution to, maybe I'm missing something.
Basically, if I'm in section 1, a button tells section 1 to load up a diagram specific to section 1. It also checks to see if section 2 is loaded, and removes it.
It I'm in section 2, a button tells section 2 to load up a diagram specific to section 2. It also checks to see if section 1 is loaded, and removes it.
If I'm in neither, the button goes away.
So, on first load, that all works fine.
Here's where bug begins:
User goes from section 1, to section 1 diagram, to section 2, to section 2 diagram, back to section 1, section 1 diagram. Section 1 loads up, but section 1 diagram gets replaced with section 2 diagram.
Again, this only happens after I've clicked on each one once. If I go from section 1, to section 1 diagram, to a section without a diagram, back to section 1 diagram, that all works.
Sorry if this sounds confusing, but it's part of a very large app that I can't upload.
Here's a snippet of code. See anything glaring that I'm missing?
ActionScript Code:
if(section == "Section 1"){
btn.visible = true;
btn.btnTxt.text = "Section 1";
btn.addEventListener(MouseEvent.CLICK, loadSection1Diagram);
}else if (section == "Section 2"){
btn.visible = true;
btn.btnTxt.text = "Section 2";
btn.addEventListener(MouseEvent.CLICK, loadSection2Diagram);
}else{
btn.visible = false;
}
private function loadSection1Diagram(e:MouseEvent) {
//check to see if any diagrams are still loaded and remove them
if(section2 && contains(section2)){
removeChild(section2)
}
section1 = new SectionDiagram;
addChild(section1);
}
}
private function loadSection2Diagram(e:MouseEvent) {
//check to see if any diagrams are still loaded and remove them
if(section1 && contains(section1)){
removeChild(section1)
}
section2 = new SectionDiagram;
addChild(section2);
}
}
Calling Function In Child-mc
Hi,
is the following possible, if 'yes', how?
In my main-scene i have a mc that has only one frame with a script attached to it.
Lets say the script on the frame is
//*********************
function test() {
// do something
}
//*********************
and the name of the mc is testMC.
In my main-scene i tried something like this and it did not work:
//**********************
testMC.test();
//**********************
I know that calling a parent-script works with
//**********************
_parent.parentFunction();
//**********************
So is it possible?
Thanks
Running A Function From A Child MC?
Hi all
I have a function called menuchange sitting on frame 1 of _root.pt_menu.ptmenumc.menufinal.menuchange
To run this function I would use
_root.pt_menu.ptmenumc.menufinal.menuchange();
Is that correct?
Any help would be great,
Accessing Child Function
I have a custom class named caption that extends Sprite, that takes a textField and draws a box around it essentially and by default, the alpha value is set to 0. I then want to loop through these items and have them fade in and out, so each caption (child of a Sprite called "captionLayer") has 2 functions, fadeIn() and fadeOut() which work perfectly.
I load all my captions from XML and throw them into "captionLayer" but then I cannot access them. I found this post from Senocular about child access and the workaround works (for individual children - I need to see if I can use that and loop through them).
but my question is, am I designing my flash file in the wrong way? How else would you do it?
Remove Function Is Removing Too Much PLS Help
Kind people, Here is my problem.
I have a simple menu nav system which is built from code. On the buttons that trigger all this fun are two functions, one that builds the next menu, and one that removes the lower level menus in the event that the user is clicking on a higher level button. Simple stuff.
This is where I'm running into trouble. Both of the functions seem to be working fine and doing their thing. However, the remove function is wiping the newly built menu as well, here is that function:
function removeold(theArray){
aLen = _root.awayArray[2].length;
aLen = aLen-1;
if(_root.awayArray[2][aLen] < _root.awayArray[2][aLen-1]){
for(b = _root.awayArray[2][aLen] ; b<=_root.awayArray[0].length;b++){
_root[awayArray[0][b]].removeMovieClip();
_root.awayArray[2].splice(0);
}
}
}
My suspition is that the trouble comes from the fact that I am calling the functions from one block of code, and therefore the work of the first function is taken out by the next. How can I correct this little "magic"?
thank you in advance,
Alex F
Removing An OnPress Function
Hi all...
does anyone know how to remove an onPress function completely once it's been assigned to a MC? I have a script where in one mode I want an object to be clickable, but in another it's not clickable; I can replace the onPress with an empty function, but the cursor still changes to a hand...I need the object to go dead w/o having to destroy it and re-attach it.
Removing Instance From Another Function?
Hi
hopefully someone can help me get my head around this.
I'm creating a set of tool tips on a rollover, so I've created a little tip movie with text field that's being populated from XML.
I might be doing other things around the cursor so I don't want something dragging around all the time, with that in mind I'm placing an instance of the tooltip movie on the mouse over event.
So on over event I'm calling function linkRollIn e.g.
ActionScript Code:
banBox.cover.addEventListener(MouseEvent.MOUSE_OVER,linkRollIn);
So inside linkRollIn I'm doing various rollover stuff including creating this tooltip instance:
ActionScript Code:
function linkRollIn(event:Event):void
{
event.target.gotoAndStop(3);
var tipText:TipText = new TipText();
addChild(tipText);
}
Which is all good and well. Now what's the best way to kill this instance on mouse out?
I had a play around with removeChild but of course the child was created within linkRollIn, and presumably now I am in linkRollOut it doesn't know what I'm trying to reference?
Thoughts much appreciated.
Edward.
Calling A Child's Function From The Parent Swf
Hey All...
I've tried to find the answer on this one but no luck... and I'm betting it's easier than I think? I need to target a child swf's functions from the primary swf it's loaded into.
I have a "Primary.swf" and in that I've got a movie clip called "holder" that I'm using to hold another swf called the "mp3Player.swf" thru addChild().
In that child "mp3Player.swf" there's yet another mc called "player" and in that I have a function that will pause "playerpause" the music.
I need to call that function "playerpause" from the "Primary.swf" when a person navigates to parts of the "Primary.swf" that show videos. My goal is to have the music pause while they watch and have it restart when they're done.
All I keep finding is reference on how to control the parent from the child, which is the opposite of my goals.
Any ideas?
Child/Parent Function Question.
Ive been looking for an answer to this for about 3 weeks now with very little luck.
Currently I have a scroll pane that is loading a swf, that child swf needs to tell the parent swf to run multiple mc.
Is there a way for a button within a child.swf to tell the parent.swf to run a movie clip?
Thanks in advance.
Child -> Call Function On Parent
I looked at another post similar to this, but the solution didn't seem to work for me. I have a Sprite (the parent) and another Sprite within it (the child). I have a public function called "Close" on the parent, and I want the child to be able to call this. When I put "parent.Close();" on the child, it gives me an error saying: "Call to a possibly undefined method Close through a reference with static type flash.display: DisplayObjectContainer." I used the parent property, but apparently it doesn't like somethign that I did. Does anyone know what's wrong?
Access Child.swf Function From Parent.swf
I have to access a function in child swf from parent swf. This child swf gets loaded into a canvas object in parent.swf. Everything works fine but I'm unable to call any function that was in child.swf.
My code is
Code:
var swf1:SWFLoader = new SWFLoader();
swf1.source = "CHILD.swf";
can.addchild(swf1);
I read on google and then I tried this in parent.swf's code
Code:
var myrequest:URLRequest = new URLRequest("CHILD.swf");
var myloader:Loader = new Loader();
myloader.load(myrequest);
canvas.addchild(myloader);
Now this one throws up a runtime error TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@5934b01 to mx.core.IUIComponent.
I also tried this
Code:
var myrequest:URLRequest = new URLRequest("CHILD.swf");
var myloader:Loader = new Loader();
myloader.load(myrequest);
var uic:UIComponent = new UIComponent();
uic.addChild(myloader);
canvas.addChild(uic);
But in this case my swf does not show up at all and there are no runtime errors too!
How do I resolve this error and how do I then access the function in child.swf?
PLEASE HELP GUYS.....
Access Child.swf Function From Parent.swf - 2
Hi friends,
I'm facing this disgusting problem and I'm sharing with you again for solution. I'm unable to call a child.swf's function from Parent.swf.
1. Make a new Flex project and use child.mxml as the main mxml file.
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function dummy():void
{
var i:int = 0;
i++;
}
]]>
</mx:Script>
</mx:Application>
2. Create a build using Export Release Build option.
3. Make another new project and use Parent.mxml as the mail mxml file.
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function callChildSwf():void
{
var loader:Loader = new Loader();
loader.load(new URLRequest("child.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE , callFunc);
}
private function callFunc(e:Event):void
{
(e.target.loader.content as MovieClip).dummy;
}
]]>
</mx:Script>
<mx:Button x="61" y="39" label="Button" id="btn" click="callChildSwf()"/>
</mx:Application>
4. Copy child.swf created in step 2 in second project.
5. Run the Parent.swf.
You will get a runtime error "ReferenceError: Error #1069: Property dummy not found on _child_mx_managers_SystemManager and there is no default value."
How do i solve this?
Running A Function In A Parent At The End Of A Child.swf
question: How do I call a function that is inside a parent.swf from a child external swf (class Loader)?
In my menu.swf, there is a child (Loader class) of a content.swf that gets loaded below it on run. Then when a button is clicked, it makes a string that contains the name of the content file to load next, then initiates an ending function on the child, which does some outro animation.
function buttonClick(event:MouseEvent):void
{
nextContent = event.target.name + ".swf";
MovieClip(newContent.contentLoaderInfo.content).endSequence();
}
------------------------------------------
after the ending sequence has executed in the ccontent.swf I need to know how to make a call to a function back in the menu.swf so that I can load the nextContent
Access Child.swf Function From Parent.swf
I have to access a function in child swf from parent swf. This child swf gets loaded into a canvas object in parent.swf. Everything works fine but I'm unable to call any function that was in child.swf.
My code is
Code:
var swf1:SWFLoader = new SWFLoader();
swf1.source = "CHILD.swf";
can.addchild(swf1);
I read on google and then I tried this in parent.swf's code
Code:
var myrequest:URLRequest = new URLRequest("CHILD.swf");
var myloader:Loader = new Loader();
myloader.load(myrequest);
canvas.addchild(myloader);
Now this one throws up a runtime error TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@5934b01 to mx.core.IUIComponent.
I also tried this
Code:
var myrequest:URLRequest = new URLRequest("CHILD.swf");
var myloader:Loader = new Loader();
myloader.load(myrequest);
var uic:UIComponent = new UIComponent();
uic.addChild(myloader);
canvas.addChild(uic);
But in this case my swf does not show up at all and there are no runtime errors too!
How do I resolve this error and how do I then access the function in child.swf?
PLEASE HELP GUYS.....
Access Child.swf Function From Parent.swf - 2
Hi friends,
I'm facing this disgusting problem and I'm sharing with you again for solution. I'm unable to call a child.swf's function from Parent.swf.
1. Make a new Flex project and use child.mxml as the main mxml file.
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function dummy():void
{
var i:int = 0;
i++;
}
]]>
</mx:Script>
</mx:Application>
2. Create a build using Export Release Build option.
3. Make another new project and use Parent.mxml as the mail mxml file.
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function callChildSwf():void
{
var loader:Loader = new Loader();
loader.load(new URLRequest("child.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE , callFunc);
}
private function callFunc(e:Event):void
{
(e.target.loader.content as MovieClip).dummy;
}
]]>
</mx:Script>
<mx:Button x="61" y="39" label="Button" id="btn" click="callChildSwf()"/>
</mx:Application>
4. Copy child.swf created in step 2 in second project.
5. Run the Parent.swf.
You will get a runtime error "ReferenceError: Error #1069: Property dummy not found on _child_mx_managers_SystemManager and there is no default value."
How do i solve this?
Calling A Parent Function From A Child Swf
I am working on a site right now that has a parent loader (all it contains are the menu bar [which is as3 tweened] and the functions for calling all of the other pages.) The problem that I am having right now, are some of the internal or child pages, need to call functions that are in the parent loader. For what ever reason, I am unable to do any of that.
Here is the page, so you can see what I am talking about ( http://dev.locallinux.com/mystictan/layout2.html ) and here is the loader page code:
Code:
import caurina.transitions.*;
import fl.transitions.*;
import fl.transitions.easing.*;
loaderbar.visible = false;
// Define Variables
var menuease:String = "easeOutExpo";
var menupos:String = "home";
var menutime:String = "3"
var request:URLRequest = new URLRequest("home.swf");
var myloader:Loader = new Loader ();
var thisMC:MovieClip = new MovieClip();
// Define Functions
// functions for menu items with dropdowns
function menutoperfecttan()
{
menupos = "perfecttan";
Tweener.addTween(mainmenu, {x:10, y:485, time:menutime, transition:menuease});
}
// functions for click events
function clickhome(myEvent:MouseEvent)
{
menupos = "home";
hideAll();
Tweener.addTween(mainmenu, {x:10, y:284, time:menutime, transition:menuease});
var request:URLRequest = new URLRequest("home.swf");
myloader.load(request);
};
function clickptbase(myEvent:MouseEvent)
{
if (menupos != "perfecttan")
menutoperfecttan();
var request:URLRequest = new URLRequest("ptbase.swf");
myloader.load(request);
hideAll();
}
function clickptbuild(myEvent:MouseEvent)
{
if (menupos != "perfecttan")
menutoperfecttan();
var request:URLRequest = new URLRequest("ptbuild.swf");
myloader.load(request);
hideAll();
}
function clickptboost(myEvent:MouseEvent)
{
if (menupos != "perfecttan")
menutoperfecttan();
var request:URLRequest = new URLRequest("ptboost.swf");
myloader.load(request);
hideAll();
}
// functions for mouseover events
function showHome(myEvent:MouseEvent)
{
hideAll();
this.mainmenu.hidearea.visible=true;
this.mainmenu.buttonHome.gotoAndStop("imover");
}
function showPerfectTan(myEvent:MouseEvent)
{
hideAll();
this.mainmenu.hidearea.visible=true;
this.mainmenu.dropPerfectTan.visible=true;
this.mainmenu.buttonPerfectTan.gotoAndStop("imover");
}
function showProducts(myEvent:MouseEvent)
{
hideAll();
this.mainmenu.hidearea.visible=true;
this.mainmenu.dropProducts.visible=true;
this.mainmenu.buttonProducts.gotoAndStop("imover");
}
function showOrigin(myEvent:MouseEvent)
{
hideAll();
this.mainmenu.hidearea.visible=true;
this.mainmenu.buttonOrigin.gotoAndStop("imover");
}
function showWhereToPurchase(myEvent:MouseEvent)
{
hideAll();
this.mainmenu.hidearea.visible=true;
this.mainmenu.buttonWhereToPurchase.gotoAndStop("imover");
}
function showPress(myEvent:MouseEvent)
{
hideAll();
this.mainmenu.hidearea.visible=true;
this.mainmenu.buttonPress.gotoAndStop("imover");
}
function showContact(myEvent:MouseEvent)
{
hideAll();
this.mainmenu.hidearea.visible=true;
this.mainmenu.buttonContact.gotoAndStop("imover");
}
// function for drop down and mouseover events
function hideAll()
{
this.mainmenu.dropPerfectTan.visible=false;
this.mainmenu.dropProducts.visible=false;
this.mainmenu.hidearea.visible=false;
if (menupos != "perfecttan")
this.mainmenu.buttonPerfectTan.gotoAndStop("imup");
if (menupos != "home")
this.mainmenu.buttonHome.gotoAndStop("imup");
if (menupos != "products")
this.mainmenu.buttonProducts.gotoAndStop("imup");
if (menupos != "origin")
this.mainmenu.buttonOrigin.gotoAndStop("imup");
if (menupos != "purchase")
this.mainmenu.buttonWhereToPurchase.gotoAndStop("imup");
if (menupos != "press")
this.mainmenu.buttonPress.gotoAndStop("imup");
if (menupos != "contact")
this.mainmenu.buttonContact.gotoAndStop("imup");
}
function hideMenus(e:MouseEvent): void {
hideAll();
}
// Child Movie loaders
function showProgress(event:Event):void {
loaderbar.visible = true;
}
function loadProgress(event:ProgressEvent):void
{
var percentLoaded:Number = event.bytesLoaded / event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
loaderbar.percentLoaded.text = String(uint(percentLoaded)) + "%";
}
function loadComplete(event:Event):void
{
loaderbar.visible = false;
mainbody.removeChild(thisMC);
thisMC = MovieClip(myloader.content);
myloader.unload();
mainbody.addChild(thisMC);
thisMC.gotoAndStop(1);
TransitionManager.start(thisMC, {type:Fade, direction:Transition.IN, duration:5, easing:Strong.easeOut});
}
//// Set the Style of the buttons
this.mainmenu.buttonHome.buttonMode = true;
this.mainmenu.buttonHome.useHandCursor = true;
// The Perfect Tan
this.mainmenu.buttonPerfectTan.buttonMode = true;
this.mainmenu.buttonPerfectTan.useHandCursor = true;
// The Perfect Tan - 1: Base
this.mainmenu.dropPerfectTan.base.buttonMode = true;
this.mainmenu.dropPerfectTan.base.useHandCursor = true;
// The Perfect Tan - 2: Build
this.mainmenu.dropPerfectTan.build.buttonMode = true;
this.mainmenu.dropPerfectTan.build.useHandCursor = true;
// The Perfect Tan - 3: Boost
this.mainmenu.dropPerfectTan.boost.buttonMode = true;
this.mainmenu.dropPerfectTan.boost.useHandCursor = true;
// Products
this.mainmenu.buttonProducts.buttonMode = true;
this.mainmenu.buttonProducts.useHandCursor = true;
// Products - Tan Kits
this.mainmenu.dropProducts.tankits.buttonMode = true;
this.mainmenu.dropProducts.tankits.useHandCursor = true;
// Products - 1: Base
this.mainmenu.dropProducts.base.buttonMode = true;
this.mainmenu.dropProducts.base.useHandCursor = true;
// The Perfect Tan - 2: Build
this.mainmenu.dropProducts.build.buttonMode = true;
this.mainmenu.dropProducts.build.useHandCursor = true;
// The Perfect Tan - 3: Boost
this.mainmenu.dropProducts.boost.buttonMode = true;
this.mainmenu.dropProducts.boost.useHandCursor = true;
// Origin
this.mainmenu.buttonOrigin.buttonMode = true;
this.mainmenu.buttonOrigin.useHandCursor = true;
// Where to Purchase
this.mainmenu.buttonWhereToPurchase.buttonMode = true;
this.mainmenu.buttonWhereToPurchase.useHandCursor = true;
// Where to Purchase
this.mainmenu.buttonPress.buttonMode = true;
this.mainmenu.buttonPress.useHandCursor = true;
// Where to Purchase
this.mainmenu.buttonContact.buttonMode = true;
this.mainmenu.buttonContact.useHandCursor = true;
// add Click Listneners
this.mainmenu.buttonHome.addEventListener(MouseEvent.CLICK, clickhome);
this.mainmenu.dropPerfectTan.base.addEventListener(MouseEvent.CLICK, clickptbase);
this.mainmenu.dropPerfectTan.build.addEventListener(MouseEvent.CLICK, clickptbuild);
this.mainmenu.dropPerfectTan.boost.addEventListener(MouseEvent.CLICK, clickptboost);
// add Mouse Over listners
this.mainmenu.buttonHome.addEventListener(MouseEvent.MOUSE_OVER,showHome);
this.mainmenu.buttonPerfectTan.addEventListener(MouseEvent.MOUSE_OVER,showPerfectTan);
this.mainmenu.buttonProducts.addEventListener(MouseEvent.MOUSE_OVER,showProducts);
this.mainmenu.buttonOrigin.addEventListener(MouseEvent.MOUSE_OVER,showOrigin);
this.mainmenu.buttonWhereToPurchase.addEventListener(MouseEvent.MOUSE_OVER,showWhereToPurchase);
this.mainmenu.buttonPress.addEventListener(MouseEvent.MOUSE_OVER,showPress);
this.mainmenu.buttonContact.addEventListener(MouseEvent.MOUSE_OVER,showContact);
this.mainmenu.hidearea.addEventListener(MouseEvent.MOUSE_OVER,hideMenus);
hideAll();
myloader.contentLoaderInfo.addEventListener(Event.OPEN, showProgress);
myloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
mainbody.addChild(thisMC);
myloader.load(request);
this.mainmenu.buttonHome.gotoAndStop("imover");
So the question is, how do I call one of those functions (for example clickptboost()) from a loaded swf file? I have tried this.parent.parent.clickptboost(), turned off strict mode, turned it back on, tried MovieClip(this.parent).clickptboost(). All of those fail for one reason or another.
Removing The OnRelease Function Of A MovieClip
I have a movie clip on stage and am giving it the functionality of a button via actionscript:
col1_mc.onRelease = function() {
_parent.loadPlan(this, this._parent)
};
The function loadPlan() tells the calling movieClip to play. On frame 10 of the calling movie clip are further movie clips with their own functionality, but when I go to click on one of these the parent clip's function is triggered.
How can i overcome this problem?
Thanks
How To Call A Function Defined In A Child Clip
I've got simple problem - I want to call a function which is defined inside a child movie clip, but I can't
I've attached simple movie as an example.
When I'm in a child movie and I'm calling function defined in a parent movie everything is ok, but another way around isn't.
Can anyone help?
Adam
Child Makes Parent Execute A Function?
Hello.
I have a movieclip (calendar) with a sub movie (create custom event). After I put all the information in the event screen such as date, description etc. I have a "save" button. When I click save I want the parent (calendar) to run a function called "populateEvents". Which basically looks through every day of the month to find any events. Since I just added one, it should run the function, see the new event then highlight the date.
Naturally I am having trouble with this. The child tells the parent to run the function but it ain't working.
Code:
MovieClip(this.parent).populateEvents();
That's the code I'm using and I can see in the trace window it is actually running the functions but it looks like it's trying to execute the functions from within itself, not from the parent movie so it of course will not work.
How A SWF Child Can Control A Parents Function / Variable ?
For instance, in the below code a parent can control a SWF childs function alert ().
But how a SWF child can control the parents function ReceivingChildMsg() ?
public class ChildSWF extends Sprite
{
private var t:TextField;
public function ChildSWF():void
{
t = new TextField( );
t.text = "No Message from the Parent";
addChild( t );
//~~~~~~~~~~
Button.addEventListener(MouseEvent.CLICK,clickHand ler,false,0,true);
}
public function alert(msg:String):void
{
t.text = msg;
}
protected function clickHandler(event:MouseEvent):void
{
ReceivingChildMsg (Received Child Message);
}
########
public class ParentSWF extends Sprite
{
private var loader:Loader;
public function ParentSWF():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onLoadComplete);
loader.load(new URLRequest('ChildSWF.swf'));
//~~~~~~~~~~~
tc = new TextField( );
tc.text = "No Message from the Child";
addChild( tc );
}
private function onLoadComplete(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
addChild(e.target.content);
var swf:Object = loaderInfo.content;
swf.x = 75;
swf.y = 50;
swf.alert('Received Parent Message');
}
public function ReceivingChildMsg ( var childsMsg:String):void
{
tc.text = childsMsg;
}
}
How Do I Call A Function From Inside A Child Movieclip?
hi,
i have a function on the root timeline, and i have a movieclip on the timeline. i want to call a function that is on the root timeline (so the movieclips parent). the function is called nextImage.
i have tried:
parent.nextImage();
root.nextImage();
and
var p:MovieClip = parent as MovieClip;
p.nextImage();
why don't these work, and why is it so hard in AS3.0 to do things to the root and parent timelines? i miss being able to just type parent.parent.gotoAndStop(2);
Anyway, any help would be great.
Thanks
Ben
Loading A Child Movieclip Within A Function, Getting An Error...
The code below loads a movieclip after a a set amount of time if the mouse isn't moved. The code works. I've started working on the actual screensaver, and I noticed that the animation isn't beginning when I addChild() the movieclip. It's beginning when I load it into a variable(var ss:ss_test - new ss_test)
So I tried loading it into the variable during the loadScreenSaver() function, which works, but for some reason I get an error when the endss() function runs...
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:: DisplayObjectContainer/removeChild()
at animation_fla::MainTimeline/endss()
not sure why loading the screensaver variable in the loadScreenSaver() function causes an error, but loading it outside of the function doesn't...
ActionScript Code:
var timer_screensaver:Timer = new Timer(7000, 1);
var posX:int;
var posY:int;
var ss:ss_test = new ss_test;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
timer_screensaver.addEventListener(TimerEvent.TIMER_COMPLETE, loadScreenSaver);
timer_screensaver.start();
function enterFrameHandler(event:Event):void {
if (stage.mouseX != posX) {
timer_screensaver.reset();
timer_screensaver.start();
}
posX = stage.mouseX;
posY = stage.mouseY;
}
function loadScreenSaver(event:TimerEvent) :void {
timer_screensaver.reset();
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
var ss:ss_test = new ss_test;
addChild(ss);
ss.x = 680;
ss.y = 384;
ss.addEventListener(MouseEvent.MOUSE_MOVE, endss);
}
function endss(event:MouseEvent) :void {
ss.removeEventListener(MouseEvent.MOUSE_MOVE, endss);
removeChild(ss);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
timer_screensaver.start();
}
Parent Swf Call Function In Child Swf Not Working
Hi all,
I'm having a problem with this and I just can't figure it out :( (I've been trying different things and staring at it for hours and I'm losing my mind...)
So I have a Parent swf that loads a Child swf (this goes without any problems), but I want the Parent to call a function in the child, now this is where it goes wrong...
The function the Parent has to call is named "lookupcar" and needs to give the value "wagen" with it. The problem I think is that the Parent wants to call the function but it still needs to load (correct me if I'm wrong). Is there a way to check if the Child swf is loaded completely before trying to call the function? Could you give me an example of this please? Or any other suggestions on what goes wrong?
Code in the Parent
.......
root.inhoud.createEmptyMovieClip("thetext", "thetext", this.getNextHighestDepth());
root.inhoud.thetext.loadMovie("uitrusting-wagenpark.swf");
root.inhoud.thetext.lookupcar(wagen);
Code in the Child
(the function lookupcar)
_global.lookupcar = function(carnr:String){
trace("LOOKUPCAR, with car nr: " + carnr);
......
}
Thanks in advance for all the help.
How A SWF Child Can Control A Parent’s Function/variable ?
For instance, in the below code a parent can control a SWF child’s function “alert ()”.
But how a SWF child can control parent’s function “ReceivingChildMsg()” ?
Attach Code
public class ChildSWF extends Sprite
{
private var t:TextField;
public function ChildSWF():void
{
t = new TextField( );
t.text = "No Message from the Parent";
addChild( t );
//~~~~~~~~~~
Button.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);
}
public function alert(msg:String):void
{
t.text = msg;
}
protected function clickHandler(event:MouseEvent):void
{
ReceivingChildMsg (‘Received Child Message’);
}
########
public class ParentSWF extends Sprite
{
private var loader:Loader;
public function ParentSWF():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest('ChildSWF.swf'));
//~~~~~~~~~~~
tc = new TextField( );
tc.text = "No Message from the Child";
addChild( tc );
}
private function onLoadComplete(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
addChild(e.target.content);
var swf:Object = loaderInfo.content;
swf.x = 75;
swf.y = 50;
swf.alert('Received Parent Message');
}
public function ReceivingChildMsg ( var childsMsg:String):void
{
tc.text = childsMsg;
}
}
Call A Function On Stage From Within A Child MovieClip?
Easy but not able to get it working. I have a clickable mc within another mc which is located on the main timeline. I need to call a function on the main timeline from within the clickable mc... this.parent.parent returns errors...
What am I doing wrong?
Any help?
Thanks...
How A SWF Child Can Control A Parents Function/variable ?
For instance in the below code a parent can control the SWF childs function alert ().
But how a SWF child can control parents function ReceivingChildMsg() ?
public class ChildSWF extends Sprite
{
private var t:TextField;
public function ChildSWF():void
{
t = new TextField( );
t.text = "No Message from the Parent";
addChild( t );
//~~~~~~~~~~
Button.addEventListener(MouseEvent.CLICK,clickHand ler,false,0,true);
}
public function alert(msg:String):void
{
t.text = msg;
}
protected function clickHandler(event:MouseEvent):void
{
ReceivingChildMsg (Received Child Message);
}
########
public class ParentSWF extends Sprite
{
private var loader:Loader;
public function ParentSWF():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onLoadComplete);
loader.load(new URLRequest('ChildSWF.swf'));
//~~~~~~~~~~~
tc = new TextField( );
tc.text = "No Message from the Child";
addChild( tc );
}
private function onLoadComplete(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
addChild(e.target.content);
var swf:Object = loaderInfo.content;
swf.x = 75;
swf.y = 50;
swf.alert('Received Parent Message');
}
public function ReceivingChildMsg ( var childsMsg:String):void
{
tc.text = childsMsg;
}
}
How A SWF Child Can Control A Parents Function / Variable ?
For instance, in the below code a parent can control the SWF childs function alert ().
But how a SWF child can control the parents function ReceivingChildMsg() ?
( Note: I am using Actionscript 3 )
public class ChildSWF extends Sprite
{
private var t:TextField;
public function ChildSWF():void
{
t = new TextField( );
t.text = "No Message from the Parent";
addChild( t );
//~~~~~~~~~~
Button.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);
}
public function alert(msg:String):void
{
t.text = msg;
}
protected function clickHandler(event:MouseEvent):void
{
ReceivingChildMsg (Received Child Message);
}
########
public class ParentSWF extends Sprite
{
private var loader:Loader;
public function ParentSWF():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest('ChildSWF.swf'));
//~~~~~~~~~~~
tc = new TextField( );
tc.text = "No Message from the Child";
addChild( tc );
}
private function onLoadComplete(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
addChild(e.target.content);
var swf:Object = loaderInfo.content;
swf.x = 75;
swf.y = 50;
swf.alert('Received Parent Message');
}
public function ReceivingChildMsg ( var childsMsg:String):void
{
tc.text = childsMsg;
}
}
How A SWF Child Can Control A Parent’s Function / Variable ?
For instance, in the below code a parent can control the SWF child’s function “alert ()”.
But how a SWF child can control the parent’s function “ReceivingChildMsg()” ?
( Note: I am using Actionscript 3 )
public class ChildSWF extends Sprite
{
private var t:TextField;
public function ChildSWF():void
{
t = new TextField( );
t.text = "No Message from the Parent";
addChild( t );
//~~~~~~~~~~
Button.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);
}
public function alert(msg:String):void
{
t.text = msg;
}
protected function clickHandler(event:MouseEvent):void
{
ReceivingChildMsg (‘Received Child Message’);
}
########
public class ParentSWF extends Sprite
{
private var loader:Loader;
public function ParentSWF():void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest('ChildSWF.swf'));
//~~~~~~~~~~~
tc = new TextField( );
tc.text = "No Message from the Child";
addChild( tc );
}
private function onLoadComplete(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
addChild(e.target.content);
var swf:Object = loaderInfo.content;
swf.x = 75;
swf.y = 50;
swf.alert('Received Parent Message');
}
public function ReceivingChildMsg ( var childsMsg:String):void
{
tc.text = childsMsg;
}
}
Call A Parent's Function From Child Swf /problems
hi this is the code i found out on the web to call a function in the parent swf from the loaded child swf.
in the child swf:
Code:
panel.next_mc.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void{
MovieClip(this.parent.parent).parentFunction();
}
in the main swf:
Code:
function parentFunction():void{
trace("this is the PARENT'S FUNCTION!!!");
}
this should work, however i get this error:
TypeError: Error #1034: impossible to convert flash.display::Stage@2b7e1e9 in flash.display.MovieClip.
at horiz_icons2_fla::MainTimeline/onClick()
COULD ANYONE HELP PLEASE? THANX! xmarcello
|