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




Referencing The Stage From A Loaded Swf



I am converting my website, which has a liquid interface, to as3 but I am still learning and I have a problem.I have child.swf that I load dynamically into parent.swf. When I run that I get:
Quote:




TypeError: Error #1009: Cannot access a property or method of a null object reference.




Through trial and error I found that the null object is the child.swf trying to reference the stage at several places such as stage.stageWidth. If I comment all of them out it runs error free, but it also doesn't do anything. I have tried replacing the first 'stage' with other things such as 'root.stageWidth' but no dice.I was also wonder how I can have a button in child.swf unload itself from the parent.swf?



KirupaForum > Flash > ActionScript 3.0
Posted on: 01-20-2008, 04:47 AM


View Complete Forum Thread with Replies

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

Referencing Stage From Class
Hello,
I am trying to make my first as3 class based game and so i was wondering if i could get some help. although the game wont have fancy graphics, i just would like to understand the way it works...currently, i am at a point where im getting :

1067: Implicit coercion of a value of type flash.display:Stage to an unrelated type Stage.
in my main file robot.fla, im using

var robo:robot=new robot(stage);
//var starenemy:enemy1=new enemy1(this.stage);
addChild(robo);

inside that robot.as
....
public class robot extends Sprite {
import flash.display.Stage;
private var _stage:Stage;
....
public function robot(stageRef:Stage):void {
_stage = stageRef;
...
}
amongst other things and i cant reference anything from the stage.

I think im going nuts trying to figure out how to correctly reference things to the stage. so can you take a look and guide me and tell me how i can proceed?
Attached is the zip file

Referencing A MovieClip On Stage Through XML
Hello.

I have a swf with several MovieClip instances on the stage at authoring time. For example, say I have mBuilding that contains mFloor, that in turn contains mAppartment.

I have an xml file that contains data so the swf knows what to do with the MovieClips.


Code:
//xml
<my_data>
<movie_clip1>mBuilding</movie_clip1>
<movie_clip2>mBuilding.mFloor</movie_clip2>
</my_data>

//flash
//xmlMovies is the variable contaning xml data
trace (this[xmlMovies.movie_clip1]); //correct
trace (this[xmlMovies.movie_clip2]); //"... null object or reference..."
I've been trying different things, but I'm still stumped. Can anyone give me some advice?

Thanks in advance.

Problem Referencing The Stage
I'm having a problem that's got me completely baffled. I've got a swf file in which references to the stage give mixed results. When I test the file stand-alone, there are no errors. But when I load it from another swf, I get null object reference runtime errors. I'm referencing the stage at various points in the code, but the null errors occur only at one of those points. When I do

trace(stage)

from the code that lies outside of any function (I'm using free-form code, not a class) I get "null". But when I do the same thing from within a function, I get "[object Stage]". However, if I create a new function and reference stage from within it, I get "null". It seems to me that no matter where you reference the stage within a swf, it should always produce the same results. Am I mistaken?

Referencing Stage From A Child
Hi, I'm making a test game to flesh out my AS3 knowledge. Currently, I have a main class (let's call it gameTitle) that the game runs from. I have several other classes, including GameScreen which is eventually displayed using the addChild method. The third piece of the puzzle are the game controls. This block of code contains a method that requires 'stage' as an argument (it detects keys being held down).

This particular method works fine when it's a part of the main class. I want to move it to the GameScreen class, but I'm having trouble referencing the same 'stage' property from here without getting errors. I've tried parent.stage, but I get the following error message:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at GameScreen$iinit()
at gameTitle/menuSelection()

I should note that gameScreen is the class where the method is located. And this class is initiated by the menuSelection() method which is located in the gameTitle class.

Referencing A MovieClip On Stage Through XML
Hello.

I have a swf with several MovieClip instances on the stage at authoring time. For example, say I have mBuilding that contains mFloor, that in turn contains mAppartment.

I have an xml file that contains data so the swf knows what to do with the MovieClips.

I've been trying different things, but I'm still stumped. Can anyone give me some advice?

Thanks in advance.







Attach Code

//xml
<my_data>
<movie_clip1>mBuilding</movie_clip1>
<movie_clip2>mBuilding.mFloor</movie_clip2>
</my_data>

//flash
//xmlMovies is the variable contaning xml data
trace (this[xmlMovies.movie_clip1]); //correct
trace (this[xmlMovies.movie_clip2]); //"... null object or reference..."

Referencing Objects On Stage
Ok, this is a dumb question but I'm just horribly stuck.
In my script I go toframe 5, and there are several textfields and clips on stage, but I can't reference them from my code. I get an error saying the objects don't exist.
If I move the objects of stage and just move them into place later that works but I'm pretty sure there is a better way to do it.

Any thoughts or links? I've checked around google but I don't know exactly what I should be searching for here.

Referencing To Stage, From MovieClip
Hi i've got little trouble... First files: http://rapidshare.com/files/12813666...there.rar.html

And now. How i can get from starterClass.as file to stage, and move to frame 2?

Referencing A MovieClip On Stage Through XML
Hello.

I have a swf with several MovieClip instances on the stage at authoring time. For example, say I have mBuilding that contains mFloor, that in turn contains mAppartment.

I have an xml file that contains data so the swf knows what to do with the MovieClips.

CODE//xml
<my_data>
  <movie_clip1>mBuilding</movie_clip1>
  <movie_clip2>mBuilding.mFloor</movie_clip2>
</my_data>

//flash
//xmlMovies is the variable contaning xml data
trace (this[xmlMovies.movie_clip1]); //correct
trace (this[xmlMovies.movie_clip2]); //"... null object or reference..."

Help Referencing Stage Elements
How do I go about referencing an element on the stage such as a Movie Clip from within a custom class that doesn't extend the movie clip itself.

For example if I have the following document class...

Code:

package classes
{
   import flash.display.MovieClip;
   import classes.XMLLoader;
   
   public class DocumentClass extends MovieClip
   {
      public function DocumentClass():void
      {
          var xml:XMLLoader = new XMLLoader();
      }
   }
}

and this is my XMLLoader class...

Code:

package classes
{
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
   
    public class XMLLoader
    {
        var req:URLRequest = new URLRequest("myXML.xml");
        var loader:URLLoader = new URLLoader();
      
        public function XMLLoader():void
        {
             loader.addEventListener(ProgressEvent.PROGRESS, loadProgress);
             loader.addEventListener(Event.COMPLETE, loadComplete);
             loader.load(req);
        }
       
        private function loadProgress(event:ProgressEvent):void
        {
             var percent:Number = ( 100 / event.bytesTotal ) * event.bytesLoaded;
        }

        private function loadComplete(event:Event):void
        {
             var newLoader:URLLoader = URLLoader(event.target);
        }
    }
}


If I have a dynamic text box with the instance name xml_txt inside a movie clip with the instance name xml_movie on the stage, how can I access it from within the XMLLoader class?

Referencing Movie On The Stage Error
I have a movie_clip_A and a movie_clip_A on the stage.
From a frame in movie_clip_A and using a mouse over event, i'm trying to control movie_clip_B.

I have referenced the movie clip both relative and absolutely:
this.parent.movie_clip_B.gotoandPlay(frame);
root.movie_clip_B.gotoandPlay(frame);

But I keep getting this error. When I click go to source. It jumps to an unrelated line of code all together.

The error is:

1119: Access of possibly undefined property movie_clip_B through a reference with static type flash.displayisplayObject.

What I am not doing correctly? (By the way, i have double checked my instance names and spelling)

Referencing Stage Items From Packages
Take this very basic piece of code:


ActionScript Code:
package {
    import fl.controls.Button;
    import flash.display.*;
    import flash.events.MouseEvent;
   
    public class ControlButton extends MovieClip {
       
        public function ControlButton() {
            setupButtons();
            trace("buttons setup");
        }
       
        private function setupButtons():void {
            myPauseButt.addEventListener(MouseEvent.CLICK, pauseButtHandler);
        }
       
        private function pauseButtHandler():void {
            trace("-- pauseButtHandler: pause/play clicked");
           
        }
    }
}

it just traps a button click for a button component on stage.
If you instance it in the document class, directly in the fla, it works.

Instead if you instance it in another class, defined in another package, it doesn't find the button:

1120: Access of undefined property myPauseButt.

for the record, this is how I instance ControlButton:


ActionScript Code:
var cb:ControlButton = new ControlButton();
addChild(cb);      // tried with and without this, same thing.

MORALE: What should I do to see a button component on stage from some remote class?

Having A Problem Referencing Objects On Stage ?
Hi everybody,

I am having a problem referencing two objects on stage and telling them to swap depths. I have an object called "illustration" on the stage that has two separate layers inside of it. These two layers hold "illustrationText" and "illustrationTextRed". My problem comes when I try to swap the depth of the two child objects (illustrationText, illustrationTextRed).

The code I placed on the timeline:


PHP Code:



illustration.addEventListener(MouseEvent.ROLL_OVER, onIllustrationOver);
illustration.addEventListener(MouseEvent.ROLL_OUT, onIllustrationOut);

function onIllustrationOver(event:MouseEvent):void
{
    root.illustration.swapChildren(illustrationText, illustrationTextRed);
}

function onIllustrationOut(event:MouseEvent):void
{
    root.illustration.swapChildren(illustrationText, illustrationTextRed);





Compiler errors keep getting thrown:
Access of undefined property illustrationText
Access of undefined property illustrationTextRed

Am I going about this the right way?

Thanks for your help!

-Brian

Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with a symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.

I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.

Under this type of linkage, is there a way to reference the stage width from the class?

I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.

Below is the code for my .fla file and my .as file. In the .as file you'll see the line "x = Math.random() * stage.stageWidth;". This is the line giving me problems. I could hard code it, as I do for the y variable on the next line, but I'd prefer not to in order to keep the code flexible.

I also attached the files in a zip.

Any help would be appreciated.


ActionScript Code:
//.fla code

var i:int;

for(i=0; i < 100; i++){
    var myBall:flaBall = new flaBall();
    addChild(myBall);
}


//.as code

package {
   
    import flash.display.*;
    import flash.events.Event;
   
   
    public class Ball extends MovieClip{
       
        var dx:Number;
        var dy:Number;
       
        public function Ball(){
            addEventListener(Event.ENTER_FRAME, onEnterFrame2);
            reset();
        }
       
        private function reset(){
            x = Math.random() * stage.stageWidth;
            y = Math.random() * 400;
            dx = Math.random() * 20 - 10;
            dy = Math.random() * 20 - 10;
        }
       
        private function onEnterFrame2(event:Event):void{
            move();
            checkBounds();
        }
       
        private function move(){
            x += dx;
            y += dy;
        }
       
        private function checkBounds(){
            if (x > 550 || x < 0){
                dx *= -1;
            }
            if (y > 400 || y < 0){
                dy *= -1;
            }
        }
    }
}

Referencing Added Stage Children
I am trying to reference a child I added named "userInfo_mc" with nested inputText named "inputEmail". But I am getting this error when compiling referencing the line inside the userInfoSubmit function :

1120: Access of undefined property userInfo_mc.

Any Ideas? Any help is appreciated











Attach Code

function individualAccount():void
{
var userInfo_mc:UserInfoMC = new UserInfoMC();
addChild(userInfo_mc);

userInfo_mc.emailInput.addEventListener(MouseEvent.MOUSE_OVER, showEmailInfoBubble);
userInfo_mc.emailInput.addEventListener(MouseEvent.MOUSE_OUT, hideInfoBubble);
userInfo_mc.continue_btn.addEventListener(MouseEvent.CLICK, userInfoSubmit);
}


function userInfoSubmit(event:MouseEvent):void
{
if (userInfo_mc.emailInput.text == ""){
trace("Fill this out!");
}
}

Referencing Stage From External Class
I have an external class file that extends the MovieClip class and is linked to a movieClip on the main stage. I need it to be able to access properties of other movieclips on the main stage. How could I do this. Here is what my base movieclip class that I want to access the stage with looks like. Remember, it is linked to a movieclip on the stage, if that matters...
Obviously there is more code in the class, but I removed it for the sake of simplicity.







Attach Code

package{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import Math;

public class Test extends MovieClip{

public function Test(){ //Constructor

}
}
}

Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with an symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.

I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.

Under this type of linkage, is there a way to reference the stage width from the class?

I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.

Any help would be appreciated.

Referencing Author Time Buttons On The Stage?
I have some buttons on the stage that were manually placed during authoring. They all have their own instance names manually assigned already. I need to code them thru my Document Class. How do I get reference to them?

I know how to do this if I am placing them from the library at runtime, but not this way.

Thanks

Referencing Loaded SWF?
I have made a website (see http://www.polysteelsoutheast.com , if you want t get an idea of it) where the menu is a swf file. Currently, its a different menu on each separate swf - each page has its own swf, which is an awful way to do the menu because whenever you need to update the menu its a ton of work). Therefore, I am simply trying to make a menu that looks almost exactly the same with a little square that goes over whichever menu item corresponds to the currently opened swf file and then have the correct location for that square in the "menu" swf file rather than in the individual swfs for each page. I loaded the menu into one of the pages, and I can see that its working partially (when I add a trace after the "current frame" code in the menu swf, it shows up in the actual swf) , but it will not take the x,y,h, and w information I have.

Here is what is on the menu swf:

//mb (mb stands for menu block, which is the small square I want over the particular menu item that reflects the file that this menu is currently located into)//

this.mb_btn.onEnterFrame = function() {
cX = this._x;
cY = this._y;
cW = this._width;
cH = this._height;
difY = cY-targY;
difX = cX-targX;
difW = cW-targW;
difH = cH-targH;
setProperty(this, _x, cX-(difX/5));
setProperty(this, _y, cY-(difY/5));
setProperty(this, _width, cW-(difW/5));
setProperty(this, _height, cH-(difH/5));
}

//------------when the current file is building green--------------//
if (_root.currentFrame=="buildinggreen"){
//change position of mb//
targX = 653.1;
targY = 125;
targW = 21.9;
targH = 24.1;
trace("building green page")


}

//------------when the current file is financing--------------//
if (_root.currentFrame=="financing"){
//change position of mb//
targX = 582.1;
targY = 125;
targW = 70;
targH = 24.1;

}

HERE IS THE CODE I HAVE ON THE ACTUAL SWF THAT THE MENU IS LOADED INTO:

_root.currentFrame="buildinggreen";
loadMovie("polysteelmenu.swf", "menuloader_mc");

But whenever I actually try it out, the only thing that works is the trace. The mb_btn just stays wherever I've placed it originally in the menu file.

All I need to know is what I am referencing incorrectly! Does anyone know?

Thanks!
Christy

Referencing A Loaded Movie
Can anyone help?

I have loaded a movie clip with the command;

loadMovie ("../aspect/aspect_ratio.swf", "_parent._parent.main_drop");

which works fine (I have a somewhat complicated movie going on!!). I now want to tell that movie to goto a frame from the same bit of code. I tried

tellTarget ("_parent._parent.main_drop") {
gotoAndPlay ("two");
}
but obviously this is not right.

Can anyone point me in the right direction.
Cheers
Nick

Referencing A Loaded Movie
hi

someone at work asked me about this & i have no idea

he's got library.swf with 4 movie clips that have the linkage of 'export this symbol'

there are buttons in library.swf to load in the linked movie clips, e.g.

placeHolder.attachMovie("circle", "myCircle", 2);
placeHolder.myCircle._x = -40;
placeHolder.myCircle._y = 40;

right...

library.swf is loaded into the 'placeholder' movie clip in main.swf

placeHolder.loadMovie("library.swf");

can he use any variation on the above attachMovie() code to trigger the attachMovie inside library.swf using a button inside main.swf (if that makes sense)

as i see it, the complication arises through the fact that library.swf has no instance name inside main.swf - is there any way to give a loaded movie an instance name?

i've suggested rearranging everything to use levels but it would be a lot easier not to...

any ideas anybody?...

thanks for your help

Referencing A Loaded Movie
I have a seperate movie that I load into my main movie and basically use that as a navigation system. I'm trying to reference a particular scene within the main movie from within the loaded navigation movie. I'm having trouble with the referencing. I have no problem referencing a Frame Label on the main timeline, but for some reason it won't go to a scene. I'm probably messing something up with my code, but any help would greatly be appreciated!!

Thanks!

[F8] Referencing Loaded Images
I have created a flash photo-gallery that is driven by XML database (none of the images are imbedded in the flash). I have created an image pre-loader with the help of some of the people here that works great. Now that I have the images loaded, I am trying to access/place the loaded images on the stage when called for in frame 2.

I have the movie split over two frames (one for the loader and the next for the gallery). The images get loaded in frame 1 and in frame 2, I need to access the loaded images for the gallery. When I run the SWF in a slower download simulation speed (56k), I see the pre-loader working on frame1. When the pre-loader is done, I tell it to go to frame 2 which is the gallery. Here however, I see that the images get downloaded again so there's a delay after the pre-loader before the first image is displayed.

I think that the problem is in my frame2 code where I have the following:

Code:
template1_imageHolder1_mc.loadMovie(movie1);
That "loads" movie1 again even though it was just loaded in frame1.

What is the best way to get aroud this issue? Is it to use loadVariables and not loadMovie because the image is already loaded? I have read about Check for Loaded Data and using the use XML.onLoad() function but it isn't very fleshed out unfortunately.

Thanks.
B

Referencing Loaded Clips
I have an index file which loads he navigation and home page files like this

//create home page holder
this.createEmptyMovieClip ("rotateClip", this.getNextHighestDepth ());
//load homepage
rotateClip.loadMovie ("home.swf", [GET]);
//create nav holder
this.createEmptyMovieClip ("navClip", this.getNextHighestDepth ());
//load navigation
navClip.loadMovie("navigation.swf");
I then load the services page replacing the home page by referencing rotateClip from the loaded nav file attaching this code to the services button

on (release) {
_root.rotateClip.loadMovie("services.swf");
}

The services page has sub sections which I load in the same way as the home page. They load fine once services page is loaded like so

on (release) {
_root.rotateClip.loadMovie.servHolder.loadMovie("servMgmt_mc.swf);


}

servHolder is to services what rotateClip is to the index page.

How can I get it to work if the user hasn't loaded the services page?
when I put this line before it or on a preceding frame

_root.rotateClip.loadMovie("services.swf") to make sure services gets loaded the servHolder doesn't load anything

External MC Loaded On Stage, I Can Press Buttons That Are On The Stage Through It...
I'm used to AS3, and I don't have much experience in AS2. I'm trying to modify an older flash file done in AS2.

An external swf is loaded using this code...


ActionScript Code:
on(release) {
    loadMovieNum("supplimental/external.swf", 500);
}

The problem is that even though this external movie covers the whole stage, My mouse can still "see" buttons that are on the stage, and I can click them. I don't want to be able to click the buttons through my external movie. Thanks for any help.

External MC Loaded On Stage, I Can Press Buttons That Are On The Stage Through It...
An external swf is loaded using this code...


Code:
on(release) {
loadMovieNum("supplimental/external.swf", 500);
}
The problem is that even though this external movie covers the whole stage, My mouse can still "see" buttons that are on the stage, and I can click them. I don't want to be able to click the buttons through my external movie. Thanks for any help.

Referencing Button Inside A Loaded SWF
Hey everyone,

I'm completely new to ActionScript and have been learning what I can in bits and pieces today. I'll try to keep my problem simple. In my main movie, I have a button that loads a second swf (small window) file into the main movie. The second file "flies" in from the bottom using motion easing. I've accomplished everything fine so far except that when I press close on the popup, it abruptly disappears.

I thought I could use yoyo() to reverse the animation when close is clicked to hide the popup off screen until I need it again. I just don't know how I'm supposed to reference the close button in the second movie from the first one.

The button in the second movie instance is Exit while its class is ExitButton. To accomplish what I'm trying to do I should set up an event listener in the main movie and remove the one from the second correct?

ActionScript Code:
wbutton.buttonMode=true;
wbutton.addEventListener(MouseEvent.CLICK,onClick);
function onClick(event:MouseEvent):void {
    var box:Loader= new Loader();
    var urlrHome:URLRequest = new URLRequest("popup.swf")
    addChild(box);
    var myTween:Tween = new Tween(this, "y",Exponential.easeOut, 600, 0, 1, true)
    box.load(urlrHome);
}

Referencing One Of A Series Of Loaded Clips
Here's an example of a series of MovieClips being loaded into a container clip:

Code:
for(var i:int=0;i<10;i++){
var dotClip:Dot = new Dot();
dotClip.y = i*dotClip.height + 5;
holder1.addChild(dotClip);
}
In attempting to affect one particular loaded clip, I've got this:

Code:
var dots:Array = new Array();
for(var i:int=0;i<10;i++){
var dotClip:Dot = new Dot();
dotClip.y = i*dotClip.height + 5;
holder1.addChild(dotClip);
dots.push(dotClip);
}
dots[5].x = -25;
My question is, is there a way to refer to that sixth dot without having to create an array and push all the dots into it? I'm trying to migrate from the AS2 attachMovie() . Many thanks!

Referencing Movie Clip Not Same When SWF Loaded Into SWF
This code is based on the _droptarget info in the Actionscript 2.0 language reference. It works fine by itself but breaks when the SWF is loaded into another SWF. Note that I uses the _lockroot property to keep the _root of the loaded clip.

I've isolated the problem to the "if" condition. The player doesn't seem to recognize the equivalence of the names. But when debugging with Trace, the names are identical.

The desired result is to have the drag object snap to the target object when dropped on the target but snap back to its origin if not on target. It works in 6, but the drag object snaps back to its origin 7 - as if it was not dropped on the target object.









Attach Code

this._lockroot = true;
origX = garbage_mc._x;
origY = garbage_mc._y;
targX = trashcan_mc._x;
targY = trashcan_mc._y;
garbage_mc.onPress = function() {
this.startDrag();
};
garbage_mc.onRelease = function() {
this.stopDrag();
if (eval(this._droptarget) == trashcan_mc) {
this._x = targX;
this._y = targY;
} else {
this._x = origX;
this._y = origY;
}
};

























Edited: 11/10/2006 at 07:07:59 AM by raylaur

Referencing BitmapData Loaded With MovieClipLoader()
The starting point is that I load an external PNG file into an open SWF application with the following code:
---------------------------------------
var loadListener:Object = new Object();
loadListener.onLoadInit = function():Void {
//do certain actions - not relevant for my question
};
var pngLoader:MovieClipLoader = new MovieClipLoader();

pngLoader.addListener(loadListener);

var mc1:MovieClip = this.createEmptyMovieClip("mc1", this.getNextHighestDepth());

pngLoader.loadClip("http://memetic-tv.net/temp/flower02.png", mc1);
---------------------------------------

That works fine. The problem is how can I later reference to 'flower02.png'
as BitmapData which is loaded as a movieClip into the movieClip 'mc1' to execute certain BitmapData methods like in particular 'copyPixels()'?

I'm aware that I could use:
---------------------------------------
import flash.display.BitmapData;

var libId:String = "flower";
var flowerBmp:BitmapData = BitmapData.loadBitmap(libId);
---------------------------------------
In this way I could reference my BitmapData by its variable identifier 'flowerBmp'. But this would require that my 'flower02.png' is already in the library which is not possible for my purpose.

For any work-arounds and clues I would be very grateful.

thanx

Referencing Variables In A Loaded Movie
Hi,
I'm playing with a Flash library in php called Ming, but it should work much the same as files made in Flash. I also have Flash at my disposal. I'm limited to an older version of Ming, and I think Actionscript 1.0, which doesn't help matters.
When I use LoadMovieNum to load a 'normal' movie (made in Flash MX 04, not generated through Ming) into level 1, it works and shows up fine.
When I try to remove it, however, it doesn't want to know. I'm using UnloadMovieNum(1), which I thought should work.
The second problem I'm having is that I was hoping I'd be able to reference a variable set in the loaded movie. I've been trying to get at the variable 'count' in the loaded movie through _level1.count, as well as trying _root on the beginning and such, and that's not getting me anywhere.
Is this possible? Any ideas would be appreciated.

Referencing Root Timeline Within Loaded Movie
Hi, I've got a movieclip that's going to be loaded by the main stage and I'd like to know what the correct path would be inside the clip to access it's local main stage, since _root will be the parent movie clip.
The module worked fine on its own when I made _root references but now that it is to be loaded by another movie I have to replace _root with a different path. I'm somewhat familiar with levels and have been trying different things but to no avail.

Referencing Function In Main Timeline From Loaded .swf
Hi,

I have a movie where I'm loading a .swf using placeholderMC.loadMovie("somemovie.swf");

Once the movie is loaded, I tell it to play, and it plays.

However, I'm needing to know when this movie has finished playing.

I put some code in the last frame of "somemovie.swf" to call a function in the main timeline.

_root.someFunction();

But it won't work.

How do I call the main timeline from a loaded .swf.

Thanks,

The Alchemist

Referencing Dynamically Loaded Clips/objects
I've been playing around with building a tile based game after checking out a couple tutorials.. I've established an overhead level with a moveable character and static objects within that environment. My problem is, that I can't seem to properly reference the character or objects (enemy0-7) within a function of the frame. I've tried a variety of possible references (_root.clip.char, etc..) to no avail.. I've attached the FLA (put the map below). Anyone have any ideas?

Thanks,
Shawn

the map is a text file named map.as located in the same folder as the swf.. map works fine.. Here's what's in map.as:

map = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1],
[1,0,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] ];

// startPosition [x,y]
startPos = [9,14];

// enemys startPositions [x,y]
enemys = [[2,1],[18,2],[9,8],[6,15],[12,18],[10,12],[15,15]];

Referencing Subclips In Dynamically Loaded Swfs?
Hi,

I'm trying to reference a subclip in a .swf file that I'm loading into an empty movieclip on the root of my main movie.

Using createEmptyMovieClip, I'm creating a movieclip called Clip on the root of my main movie.

Then, using Clip.loadmovie, I'm loading a .swf file called Clip1.swf.
This part works, because I can see the loaded file in the main movie.

Now for the part that doesn't work: In Clip1.swf is a movieclip called Shape1.

From the actionscript in the main movie, I'm trying to reference this Shape1 movieclip in the loaded .swf file in the following way:

Clip.Shape1.onRelease = function(){
trace ("It works");
}

I've also tried:

Clip1.Shape1.onRelease = function(){
trace ("It works");
}

But neither seem to work.
So, how do I reference this movieclip in my loaded movie???

Thanks,
Aragorn

Problems With Referencing A Sound Object From A Loaded Mc
hey all. i have a flash file that has the following code in the first frame of the root layer:

Object.env=this;
// store the micro-sounds in an array
totalSounds=16;
soundArray=new Array();
for (i=0;i<totalSounds;i++) {
s=new Sound();
s.attachSound("s"+i+".mp3");
soundArray[i]=s;
}

essentially i have 16 audio clips that i want to reference at various points later in the movie. everything works fine. the code is working nicely. however, i have to ultimately stuff this mc into a shell mc - the shell mc is present when the user enters the page, and when they roll over it, the main mc is pulled into the shell mc like this:

loadMovieNum(movie,1);

when i do this, none of the sounds work. i know it doesnt have to do with root references, because whenever i make a reference to the sound, i do so like this: Object.env.soundArray[x].start()

does anyone know what the problem is? help!

Cheers
j

Referencing Loaded External Swf For Button Behavior
Howdy

How does one reference an external swf file that has been loaded into a targeted blank movie clip? Here's the deal. I have several buttons that load external swf and that works fine. I would like to disable and fade back the button if the button's movie has loaded. I can get the buttons to fade and disable but I'd like for them to "come back" after another button is pressed. I just can't figure out how to check if the loaded movie is there.

Any help would be great.
Thanks.

Referencing _root Variables From Within Externally Loaded SWF
Hi,

What I'm about to ask may seem obvious, and probably has been answered before, but I've been searching and researching for a while, and just can't see where I'm going wrong.

I am trying to build a Desktop style application in Flash using a standard drop down menu, and load new content screens from external SWF's based on what was selected from the menu.

In the root timeline, I use the following actionscript to create a new movie clip and load external SWF's

code:
this.createEmptyMovieClip("mainContent",10000);

//Load Movie Clips for each Page

function loadPage(clipToLoad, pageTitle) {

_root.pageNumber++;

mainContent.loadMovie(clipToLoad);

mainContent._x = 50;
mainContent._y = 130;
topmessage = pageTitle;

}


However, within the external SWF's, I wish to populate the UI Controls via array elements held on the main timeline (the array is created from an XML file loaded into the main timeline). I need to do this, as many of the default values will change from time to time.


However, I can't seem to be able to reference what I want to from the external SWF. For example, I would attach the following to a combo box element in the external SWF:

code:
onClipEvent(load) {


// auditorControls is the name the array holding details for all controls

for(z=0; z < _parent.auditorControls.length; z++) {
if _parent.auditorControls[z].controls == "dob_day") {this.addItem({label: _parent.auditorControls[z].display, data: _parent.auditorControls[z].internal});}
}
}



I can't publish this, as I get the error:

Scene 1, Binding between <unknown>.. and dob_day.dataProvider.: The endpoint of the binding does not exist
**Error**

However, if I change '_parent' to '_root', it seems to be looking on its own timeline, not the main timeline.

I guess what I am asking is how can I load an external SWF, and bind several controls to data held within an array on the main _root timeline ?

Any Suggestions?

Thanks
Neil.

Referencing External Loaded Dynamic Text
I found this tutorial on Kirupa that explains how you can load and display external text loaded from a text file.
http://www.kirupa.com/developer/mx/m...ynamictext.htm

They place code on buttons that loads seperate text files into a dynamic text field in the flash app.

Here is the code for the button

Code:
on (release) {
loadText = new loadVars();
loadText.load("TEXT1.txt");
loadText.onLoad = function(success) {
if (success) {
// trace(success);
newsBox.html = true;
newsBox.htmlText = this.myNews;
}
};
}
I would rather use one text file for all my text and have certain pieces displayed when required.

On frame 1 of my movie I am going to need to have the loading code for my textfile. Then when I go to certain frames in my movie, I have code there that populates a textfield.

Any ideas?

Referencing Main Document Class From A Loaded Swf
Hi,
I'm loading a game swf into what is essentially a shell swf, I'd like game.swf to call a function (myFunction) in the document class of shell.swf.

At the moment I am trying to use the stage within game.swf property as a reference for shell.swf (which extends from movieclip) and then calling stage.myFunction but because the property I want to call is a custom property, it throws an error at compile time saying that the method does not exist.

Any ideas? Is it possible to do this without including the definition for the shell document class in my game.swf? Is it possible to do this without storing a reference to the shell.swf document class - i.e. being able to create the reference from within the game.swf at any desired point.

Cheers
JMC
www.funsneaks.com

Hotspots In A Loaded Movie Not Referencing Correctly
My main movie uses an onResize function to reposition movie clips relative to stage H & W, a movie loaded into level 1 contains the hotspots that aren't registering properly.

CODE IN MAIN MOVIE:
Stage.scaleMode = "noScale";
Stage.align = "TL";
///////////REPOSITION ELEMENTS WHEN STAGE IS RESIZED////////////
this.onResize();
function onResize() {
newPosition();
}
Stage.addListener(this);
function newPosition() {
stageH = Stage.height;
stageW = Stage.width;
bkgrnd_mc._width = stageW;
bkgrnd_mc._height = stageH;
main_mc._x = (stageW- main_mc._width)/2;
main_mc._y = (stageH- main_mc._height)/2;
//loaded movie- all hotspots are inside this MC:
_level1.temp_mc._x = (stageW-_level1.temp_mc._width)/2;
_level1.temp_mc._y = ((stageH-_level1.temp_mc._height)/2);
}


on loading a movie into level 1 – I can see that the hotspots contained within it are visually repositioned when browser resized (hotspots all inside ‘_level1.temp_mc’) but the x & y coordinates referenced during hitTest remain those of the original loaded movie – ignoring the fact it looks as though it has been physically repositioned!
Hit test code placed inside the loaded movie (in ‘temp_mc’) uses shapeflag method to test hits, eg:

//display readings:
_level1.temp_mc.reader_mc.onPress = function() {
this.startDrag();
};
_level1.temp_mc.reader_mc.onRelease = function() {
this.stopDrag();
if (_level1.temp_mc.hotspot1_mc.hitTest(_level1.temp_mc.reader_mc._x, _level1.temp_mc.reader_mc._y, true) {
_level1.temp_mc.temp_txt.text = " hotspot1";
}
else {
_level1.temp_mc.temp_txt.text = "Nothing detected";
}
};

Resize function also called in first frame pf loaded movie: _level0.onResize();

Any help gratefully received, thanks in advance.

Referencing Progress Bars Against Loaded Media
I'm completely new to AS3 and am having a lot of problems with it...

We have a CBT that loads multiple media files (FLV, SWF or JPGs and PNGs) and I want to show a progress bar for each file that is loaded, and when its completed, remove the progress bar.. I'm having problems referencing which progress bar goes with with media file!

I don't get how to keep track of what progress bar goes with what media.. with the event stuff being passed in, I can't seem to get a way to reference which progress bar goes with which loaded media. We can have anywhere from 1 to up to 10 peices of media being displayed on the screen.

I know this code is all messed up, but can someone look at it and see what I can do to reference this properly?









Attach Code

for(var m:uint = 0; m<mediaXML.length(); m++) {
var graphicRequest:URLRequest = new URLRequest(mediaDirectory + mediaFile);
var graphicLoader:Loader = new Loader();

graphicLoader.contentLoaderInfo.addEventListener(Event.OPEN, mediaLoadStart);
graphicLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, mediaLoadComplete);
graphicLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, mediaLoading);
graphicLoader.load(graphicRequest);

graphicLoader.x = mediaXML[m].@media_x - content_mc.x;
graphicLoader.y = mediaXML[m].@media_y - content_mc.y;
content_mc.addChild(graphicLoader);
}

// Media Functions //
function mediaLoadStart(event:Event):void {
var loadie:Loader = Loader(event.target.loader);
var loadieInfo:LoaderInfo = LoaderInfo(loadie.contentLoaderInfo);
var loadieName:String = loadieInfo.content.name;
Security.allowDomain(loadieInfo.url)

pb = new ProgressBar();
pb.move((background_mc.width - pb.width) / 2, (background_mc.height - pb.height) / 2);
pb.mode = ProgressBarMode.MANUAL;
}

function mediaLoading(event:ProgressEvent):void {
pb.setProgress(event.target.bytesLoaded, event.target.bytesTotal);
}

function mediaLoadComplete(event:Event):void {
removeChild(pb);
}

Referencing .TextField Object From A Loaded Movie?
From my main movie, I'm loading another movie that creates a text field using the createTextField command.  When I try to format the text field it will not format for some reason.  I think it's because of the way I have it referencing the object and the depth level that I have assigned it.  The textFields are created to display links loaded from a text file.  I'm creating a textFile for each link and assigning each link to it's individual depth level.  My guess is that's what causing the problem, but I don't know how to work around that.  Any suggestions?  Thanks!

height=(150-(10*totalAds))/totalAds


for (var i=1;i<=totalAds;i++){
    _root.createTextField("link_"+i,0+i,-10,height*i,50,10);
    _root["link_"+i].autoSize=true;
    _root["link_"+i].html=true;
    _root["link_"+i].htmlText=ad(i);  // was displaying italics so I changed my array to () for display purposes.
    
    linkFormat=new TextFormat();
    
    linkFormat.url="asfunction:sendURL,"+i;
    linkFormat.underline=true;
    linkFormat.color=0x000099;
    linkFormat.target="_blank";
    linkFormat.font="arial";
    linkFormat.size=12;
    linkFormat.bullet=true;
    
    _root["link_"+i].setTextFormat(linkFormat);
}
stop();

URGENT - Referencing Main.swf From External.swf Loaded With LoadMovieNum()
I've been working on this for hours and I need some help. I'm very new to Flash so I don't know if what I am trying to do is even possible. Any help would be much appreciated! Thanks in advance!


main.swf loads shirts.swf into level1 via loadMovieNum()...

i have an array in shirts.swf that main.swf can access... however, how can you get shirts.swf to access an array made in main.swf? is this possible?

-Chrissy

[CS3] Urgent: Referencing A Nested MC That Is Loaded Through FlipNavigation Component
Hi!

See FLAs here:
http://flash-it.no/div/flash/external.zip

I am trying to reference a nested MC that resides inside a swf that I load into the flipNavigation component (from flashloaded.com) externaly.

Parameters in the main movie with the component: ID=F and URL=external.swf Click the "Home" and "F" to see the flipping

Inside the external.swf I have a MC named mcStandF and inside this I have a MC named f601. Its this last MC that I try to reference. Both clips are exported in first frame.

This worked just fine when I loaded "external" as a movieClip from the library of the main movie.

I have a trace inside the swf to let me know the "_level0.flipStands.item1004.con.mc." is the path to the clip I am trying to reference.

The code I use:

Quote:




var lis = {};
lis.onInit = function(evt) {
trace("onInit");
//STAND F
var fArray = new Array("601", "603", "607", "614");
fCount = 0;
while (fCount<fArray.length) {
trace("fCount="+fCount);
//_root.flipNavigation.item1004.con._xscale = 200;
thisFstand = eval("_root.flipNavigation.item1004.con.mc.mcStand F.f"+fArray[fCount]);
thisFstand.onRollOver = function() {
trace("Over stand601!!");
trace(this._x);
this.showStand();
};
thisFstand.onRollOut = function() {
trace("Over stand601!!");
this.hideStand();
};
fCount++;
}
};
flipNavigation.addEventListener("onInit",lis);




Please help

Movieclip Referencing Another MovieClip On Stage
Hi all,
I have a movieclip with dynamically loaded content in a movieclip that sits on the stage, which works fine, it loads the content fine. Call it Clip A
I want multiple movieclips to reference this movieclips content. ie I want a copy of this Clip A to appear in multiple movieclips.

Real example
Clip A loads teamshirt Arsenal
Multiple clips to also have Arsenal teamshirt by looking at ClipA

Any ideas? Do i go about it using loadMovie and pointing it to the scene or attachMovie?

thank you in advance
Jason

Getting A Loaded MC To Remove Itself From Stage?
Hi

I'm creating an image gallery. I've got thumbnails at the bottom of the movie, which when clicked load the image into a loader ('imgLoader') above the thumbnails. I've then created a button on top of 'imgLoader' that loads up an external swf (containing a larger version of the image) into a new loader 'bigLoader' in front of the whole movie. This swf then contains a 'close' button that I want to use to remove 'bigLoader' from the stage so that is returns the user to the gallery.

Here's the code for the loaded swf:


ActionScript Code:
close_btn.addEventListener(MouseEvent.CLICK, closeClick);

function closeClick(myevent:Event):void {
    stage.removeChild(bigLoader);
}

But when I export this, I get an error saying:

"1120: Access of undefined property bigLoader.

So, I understand the error - flash cannot find bigLoader because it is in the main movie & not the external swf (where the above code is), so I just wondered if anyone knew of a way for the movie in the loader to remove itself from the stage? If the call to remove it comes from within itself?

Many thanks in advance.

Stage Access From Loaded SWF
I've searched and found similar topics, but never a solution. I apologize if this has been answered before...

I am loading an external swf using a loader. the external swf is calling the stage for a MOUSE_LEAVE event. the stage is coming back null.

does anyone know how to reference the stage from within a loaded swf?

thanks!

XML Loaded On Stage -> Movieclip
I am just trying to get a variable from XML to effect one line of code in to a movieclip. Its easier to explain if you see my code, so i am just going to paste it all here.

I bolded the AS that is the important stuff.

Stage AS:


Code:
stop();
function DisplayInfo(){
infobox_mc._visible = true;
video_btn._visible = true;
infobox_mc.content_txt.text = this.description_text;
}
function DisplayVideo() {
video_stage._visible = true;
video_stage.gotoAndPlay("start");
}
video_btn.onRelease = DisplayVideo;
video_mc.unloadMovie();
infobox_mc._visible = false;
video_btn._visible = false;
video_stage._visible = false;
var item_spacing = 25;
var item_count = 0;
function CreateMenu(menu_xml){
var items = menu_xml.firstChild.firstChild.childNodes;
for (var i=0; i<items.length; i++) {
if (items[i].attributes.type == "video") {
var title = items[i].firstChild;
var description = items[i].childNodes[1];
var date = items[i].childNodes[2];
var videoid = items[i].childNodes[3];
var item_mc = menu_mc.attachMovie("menu_item","item"+item_count, item_count);
item_mc._y = item_count * item_spacing;
item_count++;
item_mc.title_txt.text = title.firstChild.nodeValue;
item_mc.date_text.text = date.firstChild.nodeValue;
item_mc.main_btn.description_text = description.firstChild.nodeValue;
item_mc.main_btn.onRelease = DisplayInfo;
}
}
}
function CreateMenu2(menu_xml){
var currItem = menu_xml.firstChild.firstChild.firstChild;
do {
if (items[i].attributes.type == "video") {
var title = currItem.firstChild;
var description = title.nextSibling;
var date = date.nextSibling;
var videoid = videoid.nextSibling;
var item_mc = menu_mc.attachMovie("menu_item","item"+item_count, item_count);
item_mc._y = item_count * item_spacing;
item_count++;
item_mc.title_txt.text = title.firstChild.nodeValue;
item_mc.main_btn.description_text = description.firstChild.nodeValue;
item_mc.date_text.text = date.firstChild.nodeValue;
item_mc.main_btn.onRelease = DisplayInfo;
}

} while (currItem = currItem.nextSibling);
}
var video_xml = new XML();
video_xml.ignoreWhite = true;
video_xml.onLoad = function(success){
if (success) CreateMenu(this);
else trace("Error loading XML file"); // no success? trace error (wont be seen on web)
}
video_xml.load("video.xml");
Loaded MovieClip (AS is on timeline of a movieclip, which is not on the stage):


Code:
var config = new Object();
config["videoId"] = null; //the default video loaded into the player
config["videoRef"] = null; //the default video loaded into the player by ref id specified in console
config["lineupId"] = null; //the default lineup loaded into the player
config["playerTag"] = null; //player tag used for identifying this page in brightcove reporting
config["autoStart"] = true; //tells the player to start playing video on load

config["width"] = 486;
config["height"] = 412;

var movie:MovieClip = this;
var bcln:Object = new Object();
bcln.onLoadInit = function(player:MovieClip):Void {
if (player != bcPlayer) bcPlayer.unloadMovie();
bcPlayer = player;
bcPlayer.onTemplateLoaded = function() {};
bcPlayer.onTemplateLoadStart = function() {};
bcPlayer.onTemplateLoadProgress = function(bytesLoaded:Number, bytesTotal:Number) {};
};
bcln.onLoadProgress = function(player:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
// place preload feedback here for shell movie
};

config["playerId"] = *********;
config["flashId"] = "flashObj"; // determines under which id the SWF will be embedded in the HTML
System.security.allowDomain("http://admin.brightcove.com");
createPlayer(config);

function createPlayer(config) {
var servicesURL:String = "http://services.brightcove.com/services";
var cdnURL:String = "http://admin.brightcove.com";

var configItems = "";
for (var i in config) {
if (i == "flashId" || i == "width" || i == "height") continue;
configItems += "&" + i + "=" + escape(config[i]);
}

var swfFile:String = "federated_f8.swf";
var file:String = cdnURL + "/viewer/" + swfFile + "?" +
"flashId="+escape(config["flashId"])+
"&cdnURL="+escape(cdnURL)+
"&servicesURL="+escape(servicesURL)+
"&playerWidth="+escape(config["width"])+
"&playerHeight="+escape(config["height"])+
"&ord="+(new Date().getTime())+
configItems+
"&buildNumber=" + 0;

var depth:Number = this.getNextHighestDepth();
var player:MovieClip = createEmptyMovieClip("bcPlayer"+depth, depth);
if (bcPlayer == null) bcPlayer = player;
//use mcl to create a preloader for the Brightcove player
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.addListener(bcln);
mcl.loadClip(file, player);
}
As you might see, the movieclip is just essentially embed code for a brightcove player (FLV video hosting site).

I just want to have the following code:


Code:
config["videoRef"] = null;
Use this variable from the XML:


Code:
var videoid = items[i].childNodes[3];
var videoid = videoid.nextSibling;
I am sure that this isn't that complicated, I just don't know what I am doing. I copied and altered the code from the xml tutorial here, I am pretty sure. There might be a tutorial out there that shows how to do this specific thing i am trying to do, but i couldn't find it.

any help would be appreciated.

Accessing Stage From Loaded Swf
i have an audio player that uses
Code:

stage.addEventListener(MouseEvent.MOUSE_UP, dontDrag);

for a volume slider (i used this because there is no onReleaseOutside method in AS3). but once the audioPlayer swf is loaded into the main swf, the stage is no longer accessible (TypeError: Error #1009). anybody know of the proper workaround?

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