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




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?



ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 10-04-2007, 05:38 PM


View Complete Forum Thread with Replies

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

Adding Library Items To Class Packages
I want to be able to exchange the Ship object with my own custom library item/graphic and apply the animation code. No luck I studied the Jody Hall tuts here but the last one Class inheritance doesn't work. I want to physics in flash with my own graphics any help or direction would be great.
Thanks, Feel kind of stupid.
package
{


import flash.display.Sprite;
public class Ship extends Sprite
{

public function Ship()
{
draw(false);
}

public function draw(showFlame:Boolean):void
{
graphics.clear();
graphics.lineStyle(1,0xffffff);
graphics.moveTo(10,0);
graphics.lineTo(-10,10);
graphics.lineTo(-5,0);
graphics.lineTo(-10,-10);
graphics.lineTo(10,0);

if(showFlame)
{

graphics.moveTo (-7.5, -5);
graphics.lineTo(-15, 0);
graphics.lineTo(-7.5, 5);
}
}

}
}

package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

public class ShipSim extends Sprite
{
private var ship:Ship;
private var vr:Number = 0;
private var thrust:Number = 0;
private var vx:Number = 0;
private var vy:Number = 0;
public function ShipSim()
{
init();
}

private function init():void
{
ship = new Ship();
addChild(ship);
ship.x = stage.stageWidth / 2;
ship.y = stage.stageHeight / 2;
ship.draw(true);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
}

private function onKeyDown(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.LEFT :
vr = -5;
break;

case Keyboard.RIGHT :
vr = 5;
break;

case Keyboard.UP :
thrust = 0.2;
ship.draw(true);
break;

default :
break;
}
}

private function onKeyUp(event:KeyboardEvent):void
{
vr = 0;
thrust = 0;
ship.draw(false);
}

private function onEnterFrame(event:Event):void
{
ship.rotation += vr;
var angle:Number = ship.rotation * Math.PI / 180;
var ax:Number = Math.cos(angle) * thrust;
var ay:Number = Math.sin(angle) * thrust;
vx += ax;
vy += ay;
ship.x += vx;
ship.y += vy;
}
}
}

SwapChildren - Referencing The Items..?
Ok - I know I've appeared here today with a few questions - my last of the day I promise!

My doc class (Main.as) calls and builds a few graphics (doBuild.as) and some text (mainText.as).

I'm trying to target the dynamic text with a listener (in the MainText.as) and swap the graphics when clicked - trouble being that I can't seem to reference them back at all (i.e stage.swapChildren(doBuild.Navigation,doBuild.Navi gation2).
Can anyone shed light on this?

Main.as


Code:

package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.*
public class Main extends Sprite {
public function Main():void {
var doBuild = new DoBuild(this);
addChild(doBuild);

var mainText = new MainText(this);
addChild(mainText);

}
}
}
MainText.as


Code:

package {
import flash.display.MovieClip;
import flash.text.*;
import flash.events.*;
public class MainText extends MovieClip {

public function MainText(stage:Main) {
var css:StyleSheet = new StyleSheet();
var body:Object = new Object();
body.fontFamily = "Arial";
body.textIndent = 0;
css.setStyle("body", body);
var txtFld:TextField = new TextField();
txtFld.x =830;
txtFld.y =10;
txtFld.width = 100;
txtFld.multiline = true;
txtFld.wordWrap = true;
txtFld.selectable = false;
txtFld.embedFonts = true;
txtFld.autoSize = TextFieldAutoSize.LEFT;
txtFld.styleSheet = css;
txtFld.htmlText = "<body>";
txtFld.htmlText += "<span class='heading'>Text</span>";
txtFld.htmlText += "</body>";
addChild(txtFld);
txtFld.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:Event):void
{
stage.swapChildren(doBuild.Navigation,doBuild.Navigation2);

}
}
}
}
doBuild.as


Code:

package {
import flash.display.Sprite;
public class DoBuild extends Sprite {
public function DoBuild(stage:Main) {
var Navigation2:Sprite=new rightPanel2();
addChild(Navigation2);
trace("NAV2 = " + getChildIndex(Navigation2));
Navigation2.x=832;
Navigation2.y=2.4;
var Navigation:Sprite=new rightPanel();
addChild(Navigation);
trace("NAV = " + getChildIndex(Navigation));
Navigation.x=832;
Navigation.y=2.4;
}
}
}

Referencing Library Items
How do I reference items in the library (ie. an image) from actionscript?
I've a couple of images in the library that I want to use with code...

[ Flash Newbie ] Stage & Packages
Hello, I've had Flash for a while but I am more of a graphics and php coding kind of guy. I haven't done anything more than motion tweens with Flash... Anyway, I've recently (yesterday) decided that it's about time I learn some Actionscript and figured that I ought to start with v3 as it what will be used the most..

Anyway, I created a project file and linked an fla and two classes to it. Now, how can I access the packages from the stage? Must I give the package a name then import it?

Also, how do I access variables defined in them?

Thanks,
- Devon

[MX04] Referencing Items In An Array ...
I am creating an array for my data grid using the .push ...

inventory.push({Name:nameVar, PricericeVar, Add:buyVar});


I was wondering ... how do I reference the objects in that array now ... I tried doing inventory[x][y] ... but I get undefined ... I also get undefined when using inventory[x] ... and for inventory I get a list of [Object, object] ... I just want to be able to get the value of

inventory[0][Name] ... that type of thing ... no idea how.

SwapChildren - Referencing (targetting) Items..?
Bit of a problem I'm stuck on here learning AS3... Any help would be fantastic

My doc class (Main.as) calls and builds a few graphics (from DoBuild.as) and some text (from mainText.as).

I'm trying to target the dynamic text with a listener (in the MainText.as) and swap the graphics when clicked - trouble being that I can't seem to reference them back at all (i.e stage.swapChildren(doBuild.Navigation,doBuild.Navi gation2).

Can anyone shed light on this?

Main.as


Code:
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.*
public class Main extends Sprite {
public function Main():void {
var doBuild = new DoBuild(this);
addChild(doBuild);

var mainText = new MainText(this);
addChild(mainText);

}
}
}
MainText.as:

Code:
package {
import flash.display.MovieClip;
import flash.text.*;
import flash.events.*;
public class MainText extends MovieClip {

public function MainText(stage:Main) {
var css:StyleSheet = new StyleSheet();
var body:Object = new Object();
body.fontFamily = "Arial";
body.textIndent = 0;
css.setStyle("body", body);
var txtFld:TextField = new TextField();
txtFld.x =830;
txtFld.y =10;
txtFld.width = 100;
txtFld.multiline = true;
txtFld.wordWrap = true;
txtFld.selectable = false;
txtFld.embedFonts = true;
txtFld.autoSize = TextFieldAutoSize.LEFT;
txtFld.styleSheet = css;
txtFld.htmlText = "<body>";
txtFld.htmlText += "<span class='heading'>Text</span>";
txtFld.htmlText += "</body>";
addChild(txtFld);
txtFld.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:Event):void
{
stage.swapChildren(DoBuild.Navigation,DoBuild.Navigation2);

}
}
}
}
DoBuild.as


Code:
package {
import flash.display.Sprite;
public class DoBuild extends Sprite {
public function DoBuild(stage:Main) {
var Navigation2:Sprite=new rightPanel2();
addChild(Navigation2);
trace("NAV2 = " + getChildIndex(Navigation2));
Navigation2.x=832;
Navigation2.y=2.4;
var Navigation:Sprite=new rightPanel();
addChild(Navigation);
trace("NAV = " + getChildIndex(Navigation));
Navigation.x=832;
Navigation.y=2.4;
}
}
}

Pt2

*PLS HELP* Referencing SQL Query Recordset Items
ok i'm using flash remoting to connect to a CFC and returning a recordset with, for example, 2 columns and 4 rows. how do i reference the value in row 2, column 3? is the recordset being returned in the form of a multi-dimensional array? i've tried setting a variable rs to: rs = result[1][2] but to no avail...

desparately trying to get this to work- TIA

Referencing Library Items Dynamically
In AS2, it was attachMovie("libraryLinkageId"+whatever, "newName"...etc...)

I could put a string together to pull any reference in the library.

How is this done in AS3? With the new syntax, how can I pull an object out of the library when I package the name of what I want dynamically.

Example:

In the library (linkageIDs shown):

Class: Export: coughlinAction
BaseClass: flash.display.MovieClip

Class: Export: warinerAction
BaseClass: flash.display.MovieClip

Class: Export: rettonAction
BaseClass: flash.display.MovieClip

//////////////////////////////////

Then in my AS3 actions window, I am currently calling one of these three based on a user interaction.

var athleteImg:coughlinAction = new coughlinAction(); // works
addChild(athleteImg);

What I want is to be able to change what I am calling based upon the name in the library. My attempt...which doesn't work.

var athleteName:String = "coughlin";
var athleteImg = new athleteName+"Action()"; // doesn't work
var athleteImg = this[athleteName+"Action()"]; // doesn't work
addChild(athleteImg);

Thoughts?

[CS3] Dynamically Referencing A MC With Eval() And Result.items[i].name (Remoting)
Hi! (I use AS2)

I have spent all day trying to solve this referencing problem! I get data from db using Flash Remoting.. This works just fine, but when I try to use the data it doesnt work:

Code:
var thisHallNumber:String = result.items[0].hallNumber;
trace("result.items[0].hallNumber");// Outputs F

trace("type of = "+typeof (result.items[0].hallNumber));// output: string
trace(thisHallNumber.toString());// output: F
trace(typeof (thisHallNumber.toString()));// output: string


//This works just fine
_root.mcHall.mcHallContainer.boxHall.mcHallF.f603._visible = false;
//This works
var string1:String = String("F");
trace("thisHall="+eval("_root.mcHall.mcHallContainer.boxHall.mcHall"+string1));
trace(_root.mcHall.mcHallContainer.boxHall["mcHall"+string1]);

//Does not work! all output to undefined
trace("thisHallNumber.valueOf()="+thisHallNumber.valueOf());//F
trace("thisHall="+eval("_root.mcHall.mcHallContainer.boxHall.mcHall"+thisHallNumber));
trace("thisHall="+eval("_root.mcHall.mcHallContainer.boxHall.mcHall"+thisHallNumber.valueOf()));
trace("thisHall="+eval("_root.mcHall.mcHallContainer.boxHall.mcHall"+result.items[0].hallNumber));trace("thisHall="+eval("_root.mcHall.mcHallContainer.boxHall.mcHall"+result.items[0].hallNumber.valueOf()));
trace("thisHall="+eval("_root.mcHall.mcHallContainer.boxHall.mcHall"+toString(thisHallNumber)));
trace("thisHall="+eval("_root.mcHall.mcHallContainer.boxHall.mcHall"+thisHallNumber.toString()));
trace("thisHall="+eval("_root.mcHall.mcHallContainer.boxHall.mcHall"+[thisHallNumber]));trace(_root.mcHall.mcHallContainer.boxHall["mcHall"+string1]);
trace(_root.mcHall.mcHallContainer.boxHall["mcHall"+string1]);



If I create variable manually like:
var string1 = "F"; things work...

But when I try using result.items[i].mcHallName it doesnt work no matter what I try,...

Any help appreciated!
thanks!

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 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?

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)

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.

Items Not On Stage Showing
I have just created a Flash movie, and I have blank movie clips about 20 pixels off the stage that hold preloaded movie clips until I need them.

I was just looking at my SWF file in the browser and it showed the movie clips I had off the stage.

As I recall, Flash is not supposed to show items which are not on the stage, correct?

Any solutions?

External Swf - Off Stage Items?
I loading an external swf file into a movie yet in the external file contains some objects that hang over the stage (off screen) yet when I load the swf into the main movie the objects that are off screen are viewable? How can I hide them? The document size is set to117x217...

Any ideas?

Thanks,

dEVS!

Off Stage Items Appearing
Whenever I make an swf out of my fla the swf file pops up just fine and looks nice, but when you resize the swf window you can see items that were off the stage. Is there any way I can prevent this from happening? Thanks.

Items Appearing Off Stage
Hello,
This has been remarked on before but the answer given avoided the question.
If I make an amimation then publish it to the web why do items that are stored off of the stage show in the published swf? I thought I remembered reading that anything off the stage will not be shown.
Many thanks

Items Appear Off Stage When Published
I want to publish my movie at 100% so viewers can size it themselves. When I view my published movie in my browser (not live) I see objects that are beyond the stage. Any way to correct this? Thanks.

[CS3] CPU Usage And Items Off Stage
Hi,
how does flash handle items that are off stage.
I have a mc which contains 5 empty mc's
each of these has a swf loaded into it.
The main mc slides across stage moving a set distance at regular intervals bringing one of the 5 swf's into view.
pretty basic stuff.

When I expand my stage I see that the 5 swf's are always playing
With my stage its normal size is flash using CPU power to draw the 4 that are not visible (off stage) but still playing?

I ask because I sometimes get audio glitches when they slide into view.
the audio is not in the moving stuff it is in the main movie.

thanks
mark

Problem With Off-stage Items
Hi,
I'm new to flash and I have a problem. I'll try to explain the best I can...

I created a site and when I test the movie at 1024X768 it looks fine. I wanted to see it in a higher resolution so I bumped up the res on my monitor and tested the movie again. Now, I can see items that are off the stage in the browser. My understanding is that anything not on the stage will not be seen in the final movie. Is there something I have to do to ensure that the "outside the stage" area is not visible in the published swf? Thanks for any help!

Jason

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

Can't Drag Library Items To Stage On MAC
I am using Flash 5 on a MAC with OS 9.2. I am unable to drag library items to the stage. What can I do?

Kevin

Moving Multiple Items On The Stage
This is probably a dumb question, but here goes:

I need to dump the contents of all my nested mov clips to Scene1 as one flat animation. When I do, they are no longer in the right place on the stage.

- Is there a way to move multiple keyframes and tweens as a group to another point on the stage, without having to reposition every keyframe one at a time?

When I try selecting them all and grouping, it only moves what keyframes my timeline pointer is on. The rest are left to make unwanted crazy animations.

thanks for your help

Refrencing Array Items Already On Stage
i understand how the attached code works.

Code:
for (var m = 0; m<30; m++) {

thumbNails = picts.createEmptyMovieClip("thumbNails"+m, picts.getNextHighestDepth());
thumbNails.createEmptyMovieClip("thisThumb", this.getNextHighestDepth());
thumbNails.myNumber = m;
thumbNails._alpha = 50;
thumbNails.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha<100) {
this._alpha += 10;
}
if (this._alpha>=100) {
delete this.onEnterFrame;
}
};
};


The idea in this was to learn how to individually refrence each instance in the array, without having to write m[0],m[1],m[2]...etc , 30 times for each action. I also wanted to learn how to duplicate clips with a for loop..It makes since to me when i am creating mc's from AScipt

. But how do i do the same idea, with 5 different mc's are already on the stage. I am sure it starts with classifying them into an array, But from there, my head got a bit boggled.. So far, i am taking it in this direction:


Code:
var demos:Array= [mc1.demoScrollBar,mc1.demoButton,mc1.demoNeedle,mc1.demoSnap,mc1.demoSafetyPin];
var thisDemo:MovieClip;
for(var d=0;d<demos.length;d++){
thisDemo=demos[d].createEmptyMovieClip("helpButtons", this.getNextHighestDepth());

demos[d]._alpha=50;
thisDemo.index=d
thisDemo.onRollOver=function(){
clearInterval(nAlpha);
nAlpha=setInterval(alphaUp,50,demos[this]);

}
thisDemo.onRollOut=function(){
clearInterval(nAlpha);
nAlpha=setInterval(alphaDown,50,demos[this]);
}
thisDemo.onRelease=function(){
txDemo.text=myXML.firstChild.childNodes[this.index].attributes.words;
}
}
however, it seems that i am not getting how i can refrence each mc without writing demos[0], demo[1], etc for each i want to addres with the onRelease. was that confusing? any ideas?

How To Apply As3 Code To Items On The Stage
hello again...

i have to code a project in which the designer already prepared a fla file with an embedded MovieClip.
this MovieClip contains a lot of other MCs which i have to control using scripts...

this sucks a little but i have to do it anyhow.

now here is a specific problem:

there are four movieclips on the stage which should act as buttons.
they are named btn_0 to btn_3

to make them happen as buttons previously i would have coded:

Code:
for (var i =0;i<4;i++){
var btn=this["btn_"+i];
btn.id=i;
btn.onRollOver=function(){
btnOver(this.id);
}
btn.onRollOut=function(){
btnOut(this.id);
}
btn.onRelease=function(){
btnRelease(this.id);
}
}
function btnOver(id){
this["btn"+id].gotoAndStop(2)
}
function btnOut(id){
this["btn"+id].gotoAndStop(1)
}
function btnRelease(id){
this["btn"+id].gotoAndStop(3)
this.curr_btn_id=id
}

can someone nudge me into how this would be done in AS3 ?
thanks a lot!

Moving Stage Items On Resize
Does anyone know how to reposition the stage items on resize like they do on
http://www.hellohikimori.com/
I know how to just move the items onResize, but I want to have the effect of waiting till the resizing has finished before the items move, and how the items bounce in using a Tween.

Any Suggestions.

BUG? Selecting Items On Stage Causes Crash
I am able to consistently recreate the following issue, but no one else that I've spoken to has. Is anyone else having this issue? If I’m the only person in the world having this issue then it must be my machine and not Flash.

I'm on Windows XP with Flash 9. (latest updates, etc.)

Draw a box.
Select it and press F8 to make it a movie clip
Copy it and paste it 10 times (distribute across the stage)
Select all 11 movie clips and press F8 to make into another mc
(So now we have 11 mc’s, nested in a single mc)
Holding down the SHIFT key select each mc one at a time (do not marquee select.)

SOMETIMES it's OK. However, a lot of times one of the mc's I select will not highlight as selected. If I continue to click mc’s my machine will scream and power down! (No crash report, no blue screen, etc.) If I wait patiently the one mc that didn't highlight will highlight, the ones I previously selected will deselect.

***************************
This is getting on my nerves because I often get fla files from graphic designers that place everything on a single layer. My first task might be to select all of the text labels, for example, and place them on a separate layer. Yesterday I had to select 75 labels copy/move to another layer and paste one at a time!
***************************

Flash CS3 - Can't Drag Items Off Stage?
i don't know why but i can't drag anything (movieclips, shapes, etc) off of the stage. i've looked through all the settings and i can't figure out what i did wrong. please help! it's probably something trivial...

Load Items To Stage Via An Array
Hi all, I'm just trying to learn AS3 and am having some trouble ...

I have 4 library items (all movie clips), named as mc0, mc1, mc2, mc3. The linkage is set so the class name is the same.

I want to create an array with the class names in, so I have:

HTML Code:
var mcNames:Array = new Array(mc0, mc1, mc2, mc3);
I then want to be able to loop through (either using a for or if statement) and dynamically attach the items to the stage by looping through the array. So my code would be like:


ActionScript Code:
for (var i:Number = 0; i<mcNames.length; i++){
// put an instance of the movieclip on the stage that
//has the same name as the current item in the array.
//So for example, if the first item in the array is mc0,
//then the item attached to the stage will be the
//movieclip mc0 from the library --- but how do I do it????

}

Any help would be greatly appreciated

Removing Items From Stage Using RemoveChild
So, I have a file where I've added 27 movie clips to the stage using a for loop to cycle through items in an XML document. Here's the pertinent part of the code I'm using, it's AS3:


So, I end up with 27 instances of mini_mc, each named 0, 1, 2, 3, etc.

I'm trying to write code to remove them at a certain point in the movie but having problems. Here's what I'm using:


But I get this error:

ReferenceError: Error #1069: Property 0 not found on String and there is no default value.

I'm thinking I'm not referencing the "name" of the mcs properly?

Any help would be greatly appreciated! Thanks very much.







Attach Code

for(var i = 0; i < myXML.photo.length(); i++) {
mini_mc = new mcMini();
mini_mc.name = i;
mini_mc.buttonMode = true;
stage.addChild(mini_mc);
}

for(var i = 0; i < myXML.photo.length(); i++) {
stage.removeChild(mini_mc.name(i));
}

Accessing Stage Items Through Doc. Class
Hi there. Super Quick question:

If I drag library items onto the stage, can I access those specific instances through my document class? Or do I have to place everything on the stage with actionscript?

Removing Items From Stage With RemoveChild
So, I have a file where I've added 27 movie clips to the stage using a for loop to cycle through items in an XML document. Here's the pertinent part of the code I'm using, it's AS3:

for(var i = 0; i < myXML.photo.length(); i++) {
mini_mc = new mcMini();
mini_mc.name = i;
mini_mc.buttonMode = true;
stage.addChild(mini_mc);
}

So, I end up with 27 instances of mini_mc, each named 0, 1, 2, 3, etc.

I'm trying to write code to remove them at a certain point in the movie but having problems. Here's what I'm using:

for(var i = 0; i < myXML.photo.length(); i++) {
stage.removeChild(mini_mc.name(i));
}

But I get this error:

ReferenceError: Error #1069: Property 0 not found on String and there is no default value.

I'm thinking I'm not referencing the "name" of the mcs properly?

Any help would be greatly appreciated! Thanks very much.

Brining Items To The Stage From The Library
Hi

I have three small movie clips in my library and three buttons on my stage (b1, b2 and b3)

Initally I want movie one to be displayed and then when the user clicks b2 for example I want to be able to take movie_two_mc from the library and place it on the stage, whilst removing movie one first. Then if b3 was clicked movie 2 would go and movie 3 appear.

I know these could be external swfs but these are just tiny movie clips and I would rather them stay in the main fla. I have this working at the moment by changing the movie clips visibility but this is a little messy as all clips are on the stage at the same time until I test movie.

I know about linkage in the library and I have manged to bring in a movie clip from the library using this code

Code:

this.attachMovie("one", "one_mc", 10, { _x:275 , _y:150 });

but i can't get any further.

Thanks

Ricky55

Slide Show - Random Items To Stage -help
17 slides
each slide: (each on separate layers)
image of a shool subject
static text box with subject in a second language
a button to advance to next frame
call in a picture which allows students to give a give an opinion like It's great/It's boring/I't fun etc. (this is where I need help see below)
frame label f1/f2 etc
AS on layer slpit into 17 keyframes which intructs forward button to move to the next frame (so if you are on f4 the AS says onto F5 and at frame 17 the AS sends you back to frame one again.

I have created the pictures for the opinions and made them into movieclips which only exist in the library.

How do I script it so that when I press the opinions button a random opinion movie clip comes to the stage when I run the slide show?

Make it obvious if you think you can help. It it about creating variables or and array? (a little knowledgs is a dangerous thing)

I'm running MX 2000 Educational

Cheers

Huw

Constraining SWF To Exact Dimensions So Items Off Stage Do Not Show
I am new to flash and feel sure there is a setting somewhere that I am missing and hope someone can help me. I am an ad developer. When I create my ads and export my swf file, it looks fine in my computer because it opens in the flash software and the window it opens in is the exact dimensions of my stage. This ad is also fine when I upload it to my site. However, when I publish a swf to send to a client for approval, they usually will be viewing that file in IE or some other browser. I have noticed that when this happens, things that are off stage often show (problem #1) and the file maximizes to the size of their browser (problem #2). What can I do to keep this from happening? I currently have the publish settings for dimension to "match movie".

Thanks in advance for the help! I love flash if I can just get it to work for me!

Referencing Array Items With An Id Pulled From The Array
I have been modifying one of the Kirupa tutorials about loading external xml data and arrays. I have it successfully working, but i would like to figure out how to take it one step further. I want to be able to designate a each item in the arrays with an id rather than an iterative variable number and cannot figure out how to do it.

This is a snippet from the xml file:

<projects>
<item>
<id>13</id>
<projectname>First Project</projectname>
<location>Anytown, USA</location>
<units>60</units>
</item>
<item>
<id>33</id>
<projectname>Second Project</projectname>
<location>Sometown, USA</location>
<units>132</units>
</item>
</projects>

I am currently populating an array this way:

total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
id[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
projectname[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
plocation[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
units[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
}

but that just gives me references to: projectname1, projectname2 etc.
I would like to figure out how to get the <id> value from the loaded xml file connected to the variable name of each item in the array so that i can refer to the variables this way: projectname13, projectname33, etc.

Does this make sense? Can anyone help?

Problem With Attaching Library Items To Stage From External Class
hello

i'm new to AS and i can't figure out why i am having this problem.
i have this item in the library (Class: Buton ; base class: flash.display.SimpleButton)

and this code in my custom class:

private var butonStg:SimpleButton;
[...]
this.butonStg = new Buton();
this.butonStg.x = 30;
this.butonStg.y = 40;
addChild(this.butonStg);


now if i trace butonStg properties (like x, y, width, height) they work just fine, but the item isn't displayed on the stage, i can't see it

can anyone help me with this?

thanks

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