ActionScript 3.0 :: Defining Variables From Parent In Child
Mar 8, 2012
im working with my main FLA and a script for it child.as i have created a variable in the parent, "svar:Number = 0;" i would like the child to be able to modify this variable when certain triggers are met i've tried something like this in the "child.as" but im assuming its probably much more complicated
[Code]...
im wondering if there is a simple command such as this to call upon an existing variable in the parent? if not, is there a way i can import the variables using the import command?
View 9 Replies
Similar Posts:
Sep 6, 2010
What's the strategy for getting a child to access variables in a parent.I have a Main class.In that class I create instances of a Unit class and save those to an array.In the Unit class, I want to access the x and y coordinates of other instances of the Unit class.So I'd like to access that array I made in the Main class.I tried:this.parent.theArray[i].xbut that doesn't work. I tried using the get command, but I don't really know how to, so my efforts failed.
View 3 Replies
Oct 14, 2011
I'm trying to access some variables from my parent in my child MC.
Parent code:
var data_history:String;
function finish_checkUp(event:Event):void{
var checkUp_stat:String;
[Code]....
Now as you can see, i have tried the trace method, but with no luck. Flash doesn't report any errors regarding the trace method, but does report the two undefined vars (data_history). Ive tried to use the trace method above all the functions, at the top of the script, still the same errors though.
View 2 Replies
May 4, 2010
I have TestA.as the base class file for my TestA.fla that has nothing but a movie clip with instance name box.
TestA.as
ActionScript Code:
package
{
import flash.events.MouseEvent;
import flash.display.MovieClip;
[Code].....
View 0 Replies
Nov 22, 2010
I have a movieclip walls and a movieclip character (both on the same timeline). I want to access and change a variable inside character from the walls timeline.
ActionScript Code:
MovieClip(parent).character.somevariable = true;
...not working.
View 2 Replies
Feb 11, 2011
Wondering how to do this:
Parent swf has a class loaded, lets call it 'GlobalUtilities'. Parent swf loads in child swf. Child swf wants to use some of the 'GlobalUtilities' class that is in the parent.
How can I accomplish this? The problem I'm having right now is, when I export the child swf, I'll just error out since it can't find the reference (obviously, since it's not loaded into the parent yet).
View 3 Replies
Jun 21, 2008
The external swf is located at:[url]....In the parent.swf, I put System.security.allowDomain(url....)When you click a button on the child.swf it's suppose to trace data from the parent.swf, but it returns undefined.What am I doing wrong? I MUST access data from the parent.swf
View 4 Replies
Apr 17, 2009
I have a Parent.swf which loads a child.swf.this is a desktop application and the problem is
while loading the child.swf i have to pass a variable from parent.swf to child swf. how can i do it.can anyone give me an implemented code.
View 9 Replies
Apr 11, 2010
i'm trying to assign a parent's variable from the parent's child
//Parent
public class Main extends Sprite
{
public var selectedSquare:Sprite;
[Code]....
i'm receiving this error, but i'm casting parent from displayObjectContainer to a Sprite so i have no idea why it's not working.
1119: Access of possibly undefined property selectedSquare through a reference with static type flash.display:Sprite.
View 2 Replies
Sep 20, 2011
I have some variables defined in a child MC:
var first_nme = data.return_first;
var second_nme = data.return_second;
var email_addr = data.return_email;
var user_domain = data.return_domain;
var user_name = data.return_username;
I'm trying to use those variables in a parent movieclip/another movieclip.
[Code]...
View 9 Replies
Oct 31, 2011
I'm having some trouble getting to grips with how a child can refer to the variables of parents. Here is my Main.as :
package
{
import flash.display.MovieClip;
public class Main extends MovieClip
[code]....
Using trace(MovieClip(parent).i) instead I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Child()
at Main()
View 2 Replies
Oct 25, 2009
From the two .as files below, I get the following error when I run: 1119: Access of possibly undefined property importantNumber through a reference with static type flash.display:Sprite.
[Code]...
View 2 Replies
Jul 26, 2010
how can I pass a variable from a parent flash file to a child flash file which it calls?We have a parent flash file which imports various child flash files based on instructions in an XML file. It's probably easier to see an example - opg2DOTcoDOTuk/flash/yay.html (replace the DOTs, couldn't post an url due to restrictions) - the text above each page, and the 'enlarge page' lightbox links are all in seperate flash files (one per double page) which are brought in, depending on the pages you are looking at, based on the instructions in an XML file which looks like this...
<page ani_swf="pages/text1.swf">pages/white.jpg</page>
<page ani_swf="pages/text1.swf">pages/0001.jpg</page>
<page ani_swf="pages/text2.swf">pages/0002.jpg</page>
<page ani_swf="pages/text2.swf">pages/0003.jpg</page>
etc, where the swf is the header flash file containing the text and one or two lightbox links, and the jpg files are the page images that appear.We had to repeat the imported child flash file because of a glitch when you go backwards through the book otherwise.
This system has been fine for us up until now but recently we've had to look at making it a dynamic system, so the content of the book can be varied depending on a variable being passed into the parent file via FlashVars...
<param name="FlashVars" value="zone=1" />
<embed src="newbook3.swf" FlashVars="zone=1" ....etc
This makes the book load an xml file called "1"). This is fine, except we also need to vary the 'enlarge page' target images to match.The 'enlarge page' links are currently hard coded into each child flash file, like this...
on (release){
getURL("javascript:SWFDelegate('imagename.jpg','Ex ample');");
}
- What we've tried so far:
1. Trying to pass the variables in querystrings from the XML
eg.
<page ani_swf="pages/text2.swf?var1=image1&var2=image2">pages/0002.jpg</page>
<page ani_swf="pages/text2.swf?var1=image1&var2=image2">pages/0003.jpg</page>
with the child flash setting it's action like this...
on (release){
var image1 = var1 + ".jpg"
getURL("javascript:SWFDelegate(image1,'Example');" );
}
I'm not sure if the syntax here is correct. We have to add the ".jpg" in here because, as far as I understand it, you can't pass "." in a querystring.
2. Passing the variables for the child into the parent
I read somewhere that variables passed to a parent are automatically available to a child. Not sure if this is true, but it didn't work for me when I tried it like...
<param name="FlashVars" value="zone=1?var1=image1&var2=image2" />
<embed src="newbook3.swf" FlashVars="zone=1?var1=image1&var2=image2" ....etc
Combined with...
on (release){
var image1 = var1 + ".jpg"
getURL("javascript:SWFDelegate(image1,'Example');" );
}
...in the child button action.
View 2 Replies
Nov 7, 2010
I have several .as files. The first that loads is Main.as;
package
{
import flash.display.MovieClip;
public class Main extends MovieClip
{
[code]....
So this MC gives the user the ability to type in their name and store it into the parents playerName variable. With the intention that I can refer to it at any point later in any other MC. It stores it okay, a trace proves that, but a problem comes when this movieclip is replaced by the new one ZoneSelector;
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
[code]....
As you can see, there's hardly anything in the this .as file. But everytime the trace(MovieClip(parent).playerName) tries to run I get the following error;
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ZoneSelector()
at Setup/onbeginGameButtonClick()
It's as if the ZoneSelector runs its entire script before the playerName is set..or something like that.
View 7 Replies
May 4, 2009
I am new to flash."I am unable to access the variables of child swf in parent swf after an action(button is clicked) is performed in child swf".
My problem is i had 2 swfs parent.swf and child .swf and i loaded the child.swf file in parent.swf using Loader class there is a textbox and a button in child.swf when we enter text in the textbox(say,notepanel_txt) and click on the button(say, mySubmit) the text present in textbox(notepanel_txt.text) is saved in the database using URLLoader and an variable called success(which is String type) must be available to parent. the code is as follows[code]...
View 8 Replies
Jul 29, 2011
I got a Parent Sprite, let's name it SpriteP, which holds inside it two other Sprites. Sprite1 and Sprite2.[code]Sprite2 is a rectangle. When I rotate it, of course, the height of its parent, SpriteP, GROWS. But I would expect that height to go back to what it should be when I'm removing Sprite2!And it does! If I remove Sprite2 while NOT being rotated, the height of the parent drops back to normal, 200.
View 10 Replies
Jun 6, 2011
i am slightly confused about the parent and child relationship. lets assume we have several different instances, what would be difference of adding them all as children of the stage and creating a parent-child hierarchy between them(other than the access path).
View 5 Replies
Jul 29, 2011
I got a Parent Sprite, let's name it SpriteP, which holds inside it two other Sprites. Sprite1 and Sprite2.
When Sprite2 is NOT rotated:
Code:
trace(SpriteP.width + ' ' + SpriteP.height); //100 250.
SpriteP.removeChild(Sprite2)
trace(SpriteP.width + ' ' + SpriteP.height); //100 200. -> works, 200 is good.
When Sprite2 is rotated at 90:
[Code].....
And it does! If I remove Sprite2 while NOT being rotated, the height of the parent drops back to normal, 200. But if I rotate Sprite2, the Parent won't update its bounds.
View 1 Replies
Mar 21, 2012
I have an empty SWF that's sole purpose is to call loadMovieNum and start the project. Each loaded movie has a few variables defined within them - unique to those loaded SWFs. Instead of declaring all the variables in each SWF can I declare all of them in one place, in the first frame of the empty loader it all starts from? I'm thinking I can then declare a variable which each loaded movie can increment as needed for me.
View 2 Replies
Feb 5, 2010
[code]All clips are squared.Ok, on the PlayerPlane, there are little soldiers, which have hotkeys. The effect I'm trying to create is I want to position the GameStage so that the currently selected soldier appears in the center of the GameClicker clip.The GameStage is movable by the player (to scan other areas of the map)by holding the CTRL key, so it's easy to kinda lose track of where your players are.I have tried using localTo Global and globalToLocal techniques, but I think I'm lost on the actual math of getting the GameStage to move the correct distance so that the selected soldier is centered to the GameClicker.[code]
View 2 Replies
Jan 3, 2010
I got a "preloader" that creates an movieclip and loads an SWF. Now in the loaded SWF i want a close button to go back to the "preloader". The preloader isn't an actuall preloader but some sort of mainclip.Now i tried this:removeChild(MovieClip(e.currentTarget).parent.pare nt.parent)But i get error:ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.at flash.display::DisplayObjectContainer/removeChild()at MethodInfo-6()
View 1 Replies
Mar 12, 2004
I posted a problem recently and I think I was asking too much too soon, I apoligise for that one. I want to try again with my problem. Basically I am making an interactive circuit builder in flash mx for 8-10 year olds (does anyone remember crocodile clips?).
[Code]...
View 8 Replies
Feb 15, 2005
Here's what I've got:
var cColor1:Color = new Color(mcBut1.mcFill);
var cColor2:Color = new Color(mcBut2.mcFill);
var cColor3:Color = new Color(mcBut3.mcFill);
var cColor4:Color = new Color(mcBut4.mcFill);
var cColor5:Color = new Color(mcBut5.mcFill);
What I'd like to do is write a loop to handle all that code in less code. So, how do I define variables using variables?
Something like:
for (var i:Number = 1; i < 6, i++) {
var cColor+i = new Color(eval("mcBut"+i).mcFill);
}
View 2 Replies
Apr 28, 2008
using the MovieClipLoader function to load in several images into various actionscript defined movieclips. These movie clips, with images loaded into them, are going to have onRelease functions associated with them which will load in a larger version of the image already loaded. As you can picture, there are a series of thumbnails, and each thumbnail needs to be clickable and load a larger version of itself into an empty clip. However, I can't seem to define variables inside of the MovieClipLoader object as it's not technically a movie clip?
How might I know which larger file to load when one of the thumbnails is clicked? All the files are named all sorts of things, aren't in any particular order (user defined from a drag-n-drog UI)... I thought I was on the right track, until I realized I couldn't define variables within the empty clip holding the thumbnails..
View 2 Replies
Feb 15, 2005
Here's what I've got:
[Code]...
What I'd like to do is write a loop to handle all that code in less code. So, how do I define variables using variables?
[Code]...
View 2 Replies
Apr 19, 2005
Is it possible to define a variable inside of function where the actual variable name will change based on what parameters the function is called with? Take a look at this code:
Code:
//define the function
function attachVid(nc, ns, curVid, vidFile) {
[Code].....
I am trying to make the net Connection and net Stream object unique each time the function is called because I am trying to play like 5 flv's on stage simultaneously. As far as I know, each video stream needs a unique net Connection and a unique net Stream object. But it doesn't seem to be working.
View 1 Replies
Sep 11, 2010
if I add a clip to the stage as a child and remove the parent and set the parent equal to null, does the child get collected and removed from memory? What if the child has an image loaded into it as its child?
In my application I'm loading a series of png images as overlays that can be tinted for customizing in this app. When I trace my memory, the basic app idles at 64,000 k. The exact second I load those overlay images it goes up to 205,000k. If I remove those clips and "clear" the stage I should go back down to 64,000 k if everything is removed and collected correctly, right? It's not, it's hanging at 215,000 k. Are my images being cached and that is the reason for the memory staying up? If so, how do I prevent that. Or upon removing the parent of the image how can I un-cache the image.
If a user switches between models and loads several different items then the application actually crashes the Flash environment because of too much memory usage. It also does the same to browsers.
View 29 Replies
Nov 11, 2009
I have a parent swf which loads many child swfs (though only one is displayed at a time). My intention was to use the loaded SWFs document class to retrieve an array of objects to be assigned a tab index, combine this with the parent's own array of objects and apply sequential tab indices to them all. But what happens is actually that the parent's objects are assigned an index, but the external swf is unaffected. In fact, the external swf retains its automatic tab indexing, when I would expect that having set a value for InteractiveObject.tabIndex, automatic tab indexing would be disabled.
I've seen similar tales elsewhere. Most posts I've read are wanting to load an external swf, give it focus and loop through those objects, then close the swf and return to looping through the parent. However I would like loop through all objects as one. including manipulating the focus manager(s), and basically fiddling with every tab-related property I know.
View 2 Replies
Sep 29, 2011
trying to on mouse over set the parent of the moused over text field to the highest depth child of its parent i tried both of these: [code] private function
[Code]...
View 3 Replies
Jan 17, 2011
I'm having a strange problem setting variables in movie clips from another (parent timeline). I run the following code from the parent movie clip to target child movie clips it contains.
setVars = function (clip, value) {
clip.val1 = value;
clip.val2 = 0;
[Code].....
I am trying to set variables in a movie clip targetted by the 'clip' argument in the setVars function but they are being traced as undefined. However, setting the function works fine. I have also tried manually defining the variables in the movie clip and am still unable to change them externally from the setVars Function.
View 3 Replies