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




Trouble Accessing Stage Instances



I hvae a Player MovieClip in the library whose base class is Player.

the Player class extends MovieClip. In the Player MovieClip i have another MovieClip with an instance name of _body. I have turned OFF the automatically declare stage instances.

In the Player class i have a declaration "public var _body:MovieClip" but it says it is null when i try to trace it.

Anyone help me out? I thought that was all I had to do in order to access stage instances in classes.

player class:

Code:
package com.scargames
{
/**
* @author:Kyle McKnight
* @date:28-JAN-08
* @purpose:
*/

import flash.display.MovieClip;

public class Player extends MovieClip
{
private var _direction:String;
private var _isWalking:Boolean;
public var _body:MovieClip;

public function Player()
{
_isWalking = false;
setDirection("right");
}

public function setDirection(dir:String):void
{
_direction = dir;
gotoAndStop(_direction);

if (_isWalking)
_body.play();
else
_body.gotoAndStop(1);
}

public function getDirection():String
{
return _direction;
}

public function setIsWalking(isWalking:Boolean):void
{
_isWalking = isWalking;

if (_isWalking)
_body.play();
else
_body.gotoAndStop(1);
}

public function getIsWalking():Boolean
{
return _isWalking;
}

public function getBody():MovieClip
{
return _body;
}
}
}



FlashKit > Flash Help > Actionscript 3.0
Posted on: 08-29-2008, 02:58 PM


View Complete Forum Thread with Replies

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

Help With Accessing Stage Instances
I hvae a Player MovieClip in the library whose base class is Player.

the Player class extends MovieClip. In the Player MovieClip i have another MovieClip with an instance name of _body. I have turned OFF the automatically declare stage instances.

In the Player class i have a declaration "public var _body:MovieClip" but it says it is null when i try to trace it.

Anyone help me out? I thought that was all I had to do in order to access stage instances in classes.

player class:

Code:
package com.scargames
{
/**
* @author:Kyle McKnight
* @date:28-JAN-08
* @purpose:
*/

import flash.display.MovieClip;

public class Player extends MovieClip
{
private var _direction:String;
private var _isWalking:Boolean;
public var _body:MovieClip;

public function Player()
{
_isWalking = false;
setDirection("right");
}

public function setDirection(dir:String):void
{
_direction = dir;
gotoAndStop(_direction);

if (_isWalking)
_body.play();
else
_body.gotoAndStop(1);
}

public function getDirection():String
{
return _direction;
}

public function setIsWalking(isWalking:Boolean):void
{
_isWalking = isWalking;

if (_isWalking)
_body.play();
else
_body.gotoAndStop(1);
}

public function getIsWalking():Boolean
{
return _isWalking;
}

public function getBody():MovieClip
{
return _body;
}
}
}

That is what I always find when I search for anything about this... which as far as I can tell is exactly what i'm doing.


Quote:




In Flash CS3, when you have instances (Movieclips) on the main timeline (Stage) with instance name on them and “Automatically declare stage instances” is off (File->Publish Setting->Flash->Actionscript 3.0 setting), You will need to declare properties for the document class with the same instance names or else you will get the error messages…

For example, if you have 2 movie clips named “box” and “circle” on the stage, in document class (Main), you will need to write like:





Code:
package
{
// Import class
import flash.display.*;

// Main
public class Main extends Sprite
{
// Properties
public var box:MovieClip;
public var circle:MovieClip;
// Constructor
function Main() {}
}
}

Trouble Accessing Instance Names On Stage
I'm really baffled and have tried everything I can think of, but am at a loss. Help from you gurus would be sooooo much appreciated.
Flash CS3, Actionscript 3, Flash Player 9. Note, all this code is in a bunch of classes, so sorry I can't put an easy snippet up here for you to look at.

I have a movieclip (holderClip_mc) with a bunch of frames of text on one layer and some controls on another layer. Some controls are buttons (using the old SimpleButton stuff), some are movieclips. The controls are sometimes visible and sometimes not depending on the text layer's needs. I have key frames on the controls layer ,and when I don't want the controls to be there, I create a blank key frame. I have 2 problems.
1) in my class code I refer to the controls using: var myNavClip_mc:MovieClip = holderClip_mc["navClip_mc"] syntax. This works fine, but when I do the same thing for the buttons var myNavButton_btn:SimpleButton = holderClip_mc["nav_btn"] I get errors. (note: nav_btn is the instance name I gave the button during author time). When I run the debugger I see that the instance name nav_btn shows up listed in the holderClip_mc instance, but the valule for nav_btn is null. I tried setting the linkage to export for Actionscript (using base class flash.display.SimpleButton), but that didn't seem to help.

2) This is an even bigger head scratcher for me. When I navigate forward in the holderClip_mc frames, I am able to access the var myNavClip_mc:MovieClip = holderClip_mc["navClip_mc"] no problem, but when I go to a frame which doesn't have that instance on it anymore and then go back to the last frame that had it, it displays fine, but I can no longer access the instance. Again, when I run the debugger, I see going forward in the holderClip that the instance navClip_mc value show sthat it is a movie clip with all it's various properties, but when I go back, the debugger shows the value of the navClip_mc instance to be null. I tried making the last frame that it was visible on a key frame too so that when I come back to it I can access it, but again, no dice, debugger still shows it as null.

Please help!!! I'm totally stuck.

Accessing Instances
Hi,
I am having troubles chaning the properties of an instance within another instance. I want to change the visability of the instance within a movie clip.

How do i define its path (target)/ access the instance when setting the property of the instance?
setProperty("target", property, value);

Cheers

Daniel

Accessing Instances
.....ok i give up!

This is a total and shameful noob question, but if i have two different instances of two different classes on the stage, how do I pass variables between them.

Accessing Instances Of DuplicateMovieClip
Hello,

This code,

var i=1;
duplicateMovieClip (_root.template, "mc"+i, i);

Creates an instance called mc1. How can I access this object in code by using a variable? For instance, I have tried mc[i] but this does not work.

Any ideas?

Thanks.

Accessing Instances With For Loops
I have a bunch of MovieClips and I want to access them using a for loop. There are 20 instances (named test_1, test_2, test_3, etc.) and i want to set a variable in each one with the for loop. How can I do this?

Accessing Loader Instances
Hi
Is there a way of storing loader instances without having to "addChild" them to a Sprite
i've got a function like this

Code:
function getImage(imageNumber:int):void
{
imageLoader = new Loader();
imageLoader.load(new URLRequest(myXML.image[imageNumber].attribute("url")));
imageLoader.name = "image_" + imageNumber;
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoadComplete);
}
...and then I have an event listener that makes a note, in an Array, that this image has loaded.


Code:
function imageLoadComplete(event:Event):void
{
var pattern:RegExp = /([0-9]+)/;
var objectName:String = event.target.loader.name;
var resultAry:Array = pattern.exec(objectName);
loadedArray[resultAry[0]] = true;
}
Is there a way of accessing this imageLoader instance, at a latertime, eg. Something like this?


Code:
mySprite.addChild(imageLoader.name("image" + loadedArray[1]));
cheers for any help

Accessing Instances From A Class
Hey guys!

Never really worked with class files like this before, and come to think of it, I don´t even know if it´s possible! Or how it´s possible anyways.

I´ve always used this.addEventListener and so on.

My question is, how do you access movieclips with instance names that is on the timeline in tha .fla you are importing the classfile into?

Is there a way to go, so you could write button_mc.addEventListener inside your .as file and have it access the function you defined in your .as file while the button_mc is inside the .fla?

Thanks in advance

/rundevo

Accessing Author Time Instances By Name
Hi,

I am trying to control the timeline of a movie clip (created at author time) which is nested within another movie clip.I have the flash compiler set to automatically declare stage instances and when I debug, I can see the children underneath the parent object, and they are not null.

I'm using: getChildByName(...) as Movie Clip

But when I try to do anything with the movie clip I get the Error 1009 ...null object reference...The object is does not appear to be null, although FP says it is. Any help or guidance to a resource on this type of thing would be great. Thanks in advance

Accessing Dynamicly Named Instances
basically I want to create or duplicate several movie clips and then arange them.

I seem to be running into a basic problem.
-------------------------
on (release) {

var i:Number

var myArr:Array = new Array();
myArr[0] = "January";
myArr[1] = "February";
myArr[2] = "March";
myArr[3] = "April";

for (i = 0; i < 3; i++) {
duplicateMovieClip(abc, myArr[i], this.getNextHighestDepth());
myArr[i]._x=50;
}

}
-----------------------

So with this script I'm running into the problem of being able to refrence the instance MC after its created. " myArr[i]._x=50; " doesnt work. Flash doesnt seem to read myArr[i] as a variable, but simply the name of an instance (which doesnt exist). So- is there a way to refrence a movie clip by using the variable i named it with?

Thanks in advance-

-sgw

Problem Accessing Nested Instances
I'm having trouble accessing instances which are inside an instance of another symbol. I don't know why this isn't working. Any help would be appreciated.


ActionScript Code:
mcQuestionFrame.btAns1.onPress = function(){
    mcQuestionFrame.gotoAndPlay("QFclose");
}
mcQuestionFrame._visible = false;
mcCloud1.onPress = function(){
    switch(gsExterior.questionsSeen){
        case 0:
        mcIntro._visible = false;
        mcQuestionFrame.txtQbox.text = "NOT WORKING";
        mcQuestionFrame._visible = true;
        mcQuestionFrame.gotoAndPlay("QFstart");
        break;
        default:
        break;
    }
}


mcQuestionFrame.btAns1.onPress = function does nothing.
mcQuestionFrame.txtQbox.text = "NOT WORKING"; does nothing.

I get no syntax errors of any kind. Just nothing happens as it should. The .FLA is too big (over 500k) to attach, so I'll describe how the symbols are nested.

mcQuestionFrame is an instance of a movieclip symbol: questionFrame

inside questionFrame, btAns1, btAns2, btAns3 are instances of common button symbol Oval Buttons - blue.

When I test the movie, Debug -> Objects and Variables both list
mcQuestionFrame.btAns1
mcQuestionFrame.btAns2
mcQuestionFrame.btAns3
mcQuestionFrame.txtQbox

I've done this kind of thing before, and it worked just fine. I can't figure out why I'm having trouble now.

Thanks in advance.

Accessing And Removing Other Instances' Children
I have several instances of a class. Each instance contains a background graphic, a textField, and another container with three loaded images. When the user clicks on one of the instances, the image container from the previous instance needs to be removed from the stage. I'm new to OOP and classes and I'm kind of stumped on this one. I believe it has something to do with removing the children of the stage or displaycontainer (a concept that i'm working on understanding!) but having trouble with the methods and syntax.

Here's the code in my main.fla

ActionScript Code:
import com.SMS.InitServices;

var serviceList:Array = new Array("WEB", "APPLICATIONS", "VIDEO", "PRINT");
var count:uint;

var timer:Timer = new Timer(50, serviceList.length);//create the timer
timer.addEventListener(TimerEvent.TIMER, loadBtns);
timer.start();

function loadBtns(event:TimerEvent):void {
    count = event.target.currentCount - 1;
    var serviceBtn:InitServices = new InitServices(serviceList[count], count );
    addChild(serviceBtn);
}

And here's the relevant code in the serviceBtn class:


ActionScript Code:
btn.addEventListener(MouseEvent.CLICK,loadThumbs);

function loadThumbs(event:MouseEvent):void {
// REMOVE 'thumb' movieclip from the other instances
//that are already on stage ?
       for (var p:int=0; p<thumbOnLoaderArray.length; p++)
      {
                thumb = new MovieClip;
                addChild(thumb);
                thumbOff = new MovieClip;
                thumbOn = new MovieClip;
                thumbOff.addChild(thumbOnLoaderArray[p].content);
                thumbOn.addChild(thumbOffLoaderArray[p].content);
                thumb.addChild(thumbOff);
                thumb.addChild(thumbOn);
       }
}

Accessing MovieClip Instances - This Must Be EASY
This may be the most basic of questions, but...

I'm making a software demonstration animated solely on the timeline (sorry!) because I'm playing with the CS4 3d motion tweens.

Around frame 50, I want to run a sub-animation laid out in a movieclip instance called screen_mc, and all I want to do is this:

screen_mc.gotoAndPlay(2)

I place this in an actions layer, on the same frame as my target movieclip instance.

However, I get the error "cannot access a property or method of a null object reference".

I'm sure this would have worked in AS2...

Any help much appreciated.

Accessing Objects Within Instances Of Components
I have my stage, that has an instance of the avpresence component on it,

Basically there are several webcams, all share the same properties but I want one to be different

Right, I can get to some objects within the property using the following code:

_root.mainwebcam_cc.sit_button._x = 10; _root.mainwebcam_cc.sit_button._y = 132;

_root.mainwebcam_cc.seat_video._width = 180; _root.mainwebcam_cc.seat_video._height = 135;

mainwebcam_cc is the instance and sit_button and seat_video are objects within the component, be it buttons or movie clips

There are objects I want to move on the 3rd frame within the timeline (it may or may not get to frame 3 depending on certain things but if it does, I want to be able to move the objects) the above methods don't work, is there something else I need to do?

For example, camBtn_mc appears on frame 3 within the component but

_root.mainwebcam_cc.camBtn_mc._x = 10; doesn't do anything from on the main timeline

I have to do this outside of the component as if I try and position stuff from within the component it affects all instances and not just the one I need to concentrate on.

Dave

Accessing Instances In A LoadMovie Clip
I have a main movie (main.swf).

This loads another SWF (mainchar.swf) with MovieClipLoader using:

myMCL.loadClip("serif/cap_C/mainchar.swf", 1);

In (mainchar.swf) is an instance of a movie called (option1);

How can I get it's properties (height, width etc.) or get it to play?

I've tried all kinds of approaches without any luck. Please help...

Accessing Vars And Instances Within External SWF
Love the tutorials so thanks very much.

My problem is accessing the variables and instances within an externally loaded swf file. For example, I have a main site and I load the menu into the stage using the loader class and addchild function. How do I access the variables and instances within the menu swf? With AS2 it was:

Code:
container_menu.menu_variable;
But that doesn't work with AS3. The menu file is loading fine for me and if I trace the variable within the menu file and load it into the main file and test the movie, it traces the variable fine.

Many thanks.

Accessing MC Instances Inside Loaded SWF
Ok... I feel like an idiot. Although I've been working with AS3 since the start... and for the life of me I can't seem to access a movie clip instance inside a loaded SWF! I've searched high and low. Help is much appreciated.

Here's what I have: An external SWF named map.swf. Inside that is a movie clip instance named "portland_mc". Here's my code that doesn't work:


Code:
private var _mapLoader :Loader;
private var _mapLoaded :Boolean = false;
private var _myMap :MovieClip = new MovieClip();

public function LoadMap() :void
{
_mapLoader = new Loader();
_mapLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, DoneLoading);
_mapLoader.contentLoaderInfo.addEventListener("ioError", ErrorLoading);
_mapLoader.load(new URLRequest("assets/UI/map.swf"));

function DoneLoading(evt :Event) :void
{
trace("Done loading map!");
_mapLoaded = true;
_myMap = MovieClip(_mapLoader.content);
addChild(_myMap);
_myMap.portland_mc.gotoAndStop(1); // doesn't work!!!!
}

function ErrorLoading(evt :Event) :void
{
trace("Error! - Could not load external map SWF file!");
}
}

// Assume the nav button event has been declared and bound to this handler
public function MapButtonOnClick(evt :MouseEvent) :void
{
// Make sure map content is loaded
if (_mapLoaded)
{
// Play animation of portland_mc (a MC instance inside the loaded SWF)
_myMap.portland_mc.gotoAndPlay(2); // doesn't work either!!!!
}
}
Again, any help is appreciated.

Help Accessing Dynamical Created Instances
Heya.
With my first words i want to say sorry for my bad english because i'm from germany, so i am a bit "handycapped" writing what i want to say.

My problem :

I have created instances of a Movieclip this way :

for (i=0; i<5; i++) {
duplicateMovieClip("test", "test"+i, i);
setProperty("test"+i, _y, i*25+25);
}

The Movieclip(s) own a Textfield that i want to access. But how?
Using the pointers (_root.test+i.Label.text = "Label1") don't work.

I hope you can help me.

Thanks

Accessing Vars And Instances Within External SWF
Love the tutorials so thanks very much.

My problem is accessing the variables and instances within an externally loaded swf file. For example, I have a main site and I load the menu into the stage using the loader class and addchild function. How do I access the variables and instances within the menu swf? With AS2 it was:
Code:

container_menu.menu_variable;
But that doesn't work with AS3. The menu file is loading fine for me and if I trace the variable within the menu file and load it into the main file and test the movie, it traces the variable fine.

Many thanks.

Accessing Instances On Other Frames Than The Current Frame
Hi all

I am writing Flex app where I am loading an swf file containing an animation using instances of movie clip symbols.

For simplicity lets say that the animation uses instances of the symbols A, B and C:

On frame 1 an instance of A named "a", and an instance of B named "b" are used. On frame 2 an instance of B named "b", and an instance of C named "c" are used.

Now I want to show some red dots on top of all three instances "a", "b" and "c". I do this by attaching a new instance of the movieclip symbol "RedDot" as a child on each of the instances "a", "b" and "c".

I want to achive the effect that a red dot is shown on "a", "b" and "c" in both frame 1 and 2.

However, if I do this when the current frame is 1, then I cannot access "c", and on frame 2 I cannot access "a".

It seems as if instances are declared on the frames where they are shown, but I would to access all my instances in all frames.

The funny thing is that if I attach a red dot to "b" in frame 1, then the "b" instance in frame 2 will also have the red dot.

So I am unsure about the "liftetime" of symbol instances. When I use an instance named "b" on both frame 1 and frame 2, then it seems to be the same instance, but "c" is not used/declared on frame 1, and therefore I cannot access it on frame 1.

So my question is, how can I access instances that re only used/shown/declared on other frames than the current frame ?

Hopes this makes sense...

best regards Stig

Accessing Instances Of Dynamically Generated Buttons
After generating buttons with the following for loop I am attempting (unsuccessfully) to assign actions to them like so. Error I get here is: "Access of undefined property btn0." Any clue as to what I'm doing wrong here?


Code:
var spacing:Number = 10;

for (var i:int = 0; i < 3; i++) {
var btn = new Btn;
btn.x = 145 + i*(btn.width + spacing);
btn.y = 460;
btn.alpha = .5;
btn.name = "btn"+i;
addChild(btn);
}

btn0.addEventListener(MouseEvent.MOUSE_OVER, onBtn0_Over);
function onBtn0_Over(evt:MouseEvent):void
{
trace("works");
}
Thanks / help appreciated

Problems Accessing Variables In Movie Clip Instances
I am trying to build an application that will create multiple instances of a movie clip, each with a unique width and height that will be passed from a PHP script. Each of these will be draggable and 'rotatable' on the stage. The final positions will then be recorded and saved as a jpeg on the server(through PHP). For testing locally I am just using a text file (var.txt) with the following contents...

pic_w=340&pic_h=60&ic=007

I am having problems setting the width and height of the instances using the passed variables. Below is what I have put together so far. I have an empty movie clip with the following actionscript...

onClipEvent (load) {
for (i=1; i<4; i++) {
_root.attachMovie("mainLink", "mainInst"+i, 3+i);
loadVariables("var.txt", "_root.mainInst"+i, "POST");
eval("_root.mainInst"+i)._x = 100;
eval("_root.mainInst"+i)._y = 80*i;
}
}

onClipEvent (enterFrame) {
var pic_w = parseInt(/:pic_w);
var pic_h = parseInt(/:pic_h);
for (i=1; i<4; i++) {
eval("_root.mainInst"+i).pic_w = pic_w;
eval("_root.mainInst"+i).pic_h = pic_h;
}
}


The movie clip that is called above in the attachMovie with the linkage 'mainLink' has the following actions inside of it...

this.createEmptyMovieClip("box",20);
box.moveTo(0,0);
box.lineStyle(0, 0x333333);
box.beginFill(0xCC0000, 0)
box.lineTo(100,0);
box.lineTo(100,50);
box.lineTo(0,50);
box.endFill();

// I have been trying to access the width & height variables here
setProperty("box", _width, pic_w);
setProperty("box", _height, pic_h);

box.onPress = function () {
swapDepths(15);
startDrag ("");
}
box.onRelease = function () {
stopDrag ();
}

//create some formatting for our text box
txt_format = new TextFormat();
txt_format.font = "Verdana";
txt_format.size = 12;
txt_format.color=0x000000;

//create a blank text box and set its parameters
this.createTextField("txt_box",10,0,0,0,0); // start with default values
txt_box._width = box._width;
txt_box._height = box._height;
txt_box.background = true;
txt_box.backgroundColor = 0xEEEEEE;
txt_box.variable = "ic";

txt_box._x = box._x;
txt_box._y = box._y;

//format our text box
txt_box.setNewTextFormat(txt_format);

// this is a button in the library with the linkage 'turnLink'
this.attachMovie("turnLink", "turnInst", 35);
turnInst._x = box._x + (box._width/2)-(turnInst._width/2);
turnInst._y = box._y + (box._height/2)-(turnInst._height/2);

turnInst.onRelease = function() {
swapSize(box._height, box._width);
}

swapSize = function(new_w, new_h) {
// swap the current width and height
// to give the appearance of being rotated
setProperty("txt_box", _width, new_w);
setProperty("txt_box", _height, new_h);
setProperty("box", _width, new_w);
setProperty("box", _height, new_h);

//var diff = box._width - box._height;
var diff = getProperty("box", _width) - getProperty("box",

_height);

// reset the x and y positions
setProperty("box", _x, (box._x - diff/2));
setProperty("box", _y, (box._y + diff/2));
setProperty("txt_box", _x, (txt_box._x - diff/2));
setProperty("txt_box", _y, (txt_box._y + diff/2));
}


Any help or hints for a possible solution would be greatly appreciated.

Thanks

Problems Accessing Variables In Movie Clip Instances
I am trying to build an application that will create multiple instances of a movie clip, each with a unique width and height that will be passed from a PHP script. Each of these will be draggable and 'rotatable' on the stage. The final positions will then be recorded and saved as a jpeg on the server(through PHP). For testing locally I am just using a text file (var.txt) with the following contents...

pic_w=340&pic_h=60&ic=007

I am having problems setting the width and height of the instances using the passed variables. Below is what I have put together so far. I have an empty movie clip with the following actionscript...

onClipEvent (load) {
for (i=1; i<4; i++) {
_root.attachMovie("mainLink", "mainInst"+i, 3+i);
loadVariables("var.txt", "_root.mainInst"+i, "POST");
eval("_root.mainInst"+i)._x = 100;
eval("_root.mainInst"+i)._y = 80*i;
}
}

onClipEvent (enterFrame) {
var pic_w = parseInt(/:pic_w);
var pic_h = parseInt(/:pic_h);
for (i=1; i<4; i++) {
eval("_root.mainInst"+i).pic_w = pic_w;
eval("_root.mainInst"+i).pic_h = pic_h;
}
}


The movie clip that is called above in the attachMovie with the linkage 'mainLink' has the following actions inside of it...

this.createEmptyMovieClip("box",20);
box.moveTo(0,0);
box.lineStyle(0, 0x333333);
box.beginFill(0xCC0000, 0)
box.lineTo(100,0);
box.lineTo(100,50);
box.lineTo(0,50);
box.endFill();

// I have been trying to access the width & height variables here
setProperty("box", _width, pic_w);
setProperty("box", _height, pic_h);

box.onPress = function () {
swapDepths(15);
startDrag ("");
}
box.onRelease = function () {
stopDrag ();
}

//create some formatting for our text box
txt_format = new TextFormat();
txt_format.font = "Verdana";
txt_format.size = 12;
txt_format.color=0x000000;

//create a blank text box and set its parameters
this.createTextField("txt_box",10,0,0,0,0); // start with default values
txt_box._width = box._width;
txt_box._height = box._height;
txt_box.background = true;
txt_box.backgroundColor = 0xEEEEEE;
txt_box.variable = "ic";

txt_box._x = box._x;
txt_box._y = box._y;

//format our text box
txt_box.setNewTextFormat(txt_format);

// this is a button in the library with the linkage 'turnLink'
this.attachMovie("turnLink", "turnInst", 35);
turnInst._x = box._x + (box._width/2)-(turnInst._width/2);
turnInst._y = box._y + (box._height/2)-(turnInst._height/2);

turnInst.onRelease = function() {
swapSize(box._height, box._width);
}

swapSize = function(new_w, new_h) {
// swap the current width and height
// to give the appearance of being rotated
setProperty("txt_box", _width, new_w);
setProperty("txt_box", _height, new_h);
setProperty("box", _width, new_w);
setProperty("box", _height, new_h);

//var diff = box._width - box._height;
var diff = getProperty("box", _width) - getProperty("box",

_height);

// reset the x and y positions
setProperty("box", _x, (box._x - diff/2));
setProperty("box", _y, (box._y + diff/2));
setProperty("txt_box", _x, (txt_box._x - diff/2));
setProperty("txt_box", _y, (txt_box._y + diff/2));
}


Any help or hints for a possible solution would be greatly appreciated.

Thanks

Accessing A Variable Inside A Class, And Creating Instances...
Hi all,
I have a couple of questions, I'd appreciate any help.

I've made a class which extends the movieclip class (in a seperate .as file) that has a certain variable inside it which I would like to access from the main timeline actions (of my .fla file) so I could put the var's data inside a textfield which is on the stage.

The class is public, and the var is public...
Is there a way to do it?






My other question is about that same class (called "KeyboardObject")... I've linked a movieclip from my library to my class ("KeyboardObject" as the BaseClass), and a certain name as the Class (lets say "newCar").

If I drag the movieclip to the stage (with those "class" and "baseclass" defined) then all is well and it acts as it should act (with the custom class modifications)... but when I try to create instances of the movieclip with AS, I get an error.

What I write is this:

Code:
var newObject:newCar;
newObject = new newCar();
addChild(newObject);
What I get is this (in the output-window, not the compile-errors):

Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at KeyboardObject$iinit()
at newCar$iinit()
at TheParkingJob_fla::MainTimeline/TheParkingJob_fla::frame1()
if I change the Linkage to class=newCar and baseclass=flash.display.MovieClip, then I can call an instance to the stage, but it doesn't get the custom class behaviors...

I've also tried to change the linkage to class=KeyboardObject and baseclass=flash.display.MovieClip... if I drag an instance to the stage it worked fine, if I call it from AS I get the same error.

ANY help will be much appreciated!
Thanks.

Accessing Dynamic Text Field In Multiple Instances Of Movie Clip
I have multiple instances of a movie clip (mc1 to mc10, created with DuplicateMovieClip) which contain dynamic text with a variable name "id." I want to access the various id's from my main scene.

for (i=1;i<10;i++) {
"mc"+i.id="foo";
}
DOES NOT WORK.

How would one do it?

Trouble With Scenes And Instances
Hi
I have a 2-scene MX FLA that I just can't seem to get working.
Is there any way to reset the instance count when a new scene starts?
They just seem to build up, and I don't know how to refer to one.
Also, I don't seem to be able to set depth like I'd like to - they just stop
appearing if I set a different depth - even if it is unique.
ANy comments appreciated. I stripped the FLA down to the absolute minumum.
Thanks

Having Trouble With Multiple Instances Of The Same Object
I'm relatively new to Flash Actionscript but I've been programming in OOP for years so it only took a few days to get up to speed, however I've ran into a few weird quirks that make me wonder if I'm doing something wrong.

I've got a single scene, a main timeline within that scene and within certain frames of the main scene I've got mc's that play based on Actionscript commands. All of that works fine until I get into one of the mcs. Within them I have buttons defined on certain frames and I've assigned instance names to those buttons.

The problem is when I try to reuse an instance name on two different key frames. Within the parent scene it works fine, within the child mc only the first instance works. If I target a different frame that has the same button and instance name in the ActionScript, it does not work unless I rename the instance name in the second key frame. It sounds confusing so here is an example:

//Example_mc.Frame1 (keyframe1)
//Goes to frame 5 in Example_mc
this.button1_btn.onPress = function() {
gotoAndPlay(5)
}

//Example_mc.Frame10 (keyframe2)
//Should go to frame 5 in Example_mc but does not
this.button1_btn.onPress = function() {
gotoAndPlay(5)
}

//Example_mc.Frame10 (keyframe2)
//Properly goes to Frame5 after renaming button1 instance to button1a
this.button1a_btn.onPress = function() {
gotoAndPlay(5)
}

In the example above, when button1_btn is pressed frame 1 is properly displayed. When I try to reuse the button and button instance in frame 10, the button does not work until I rename the instance name to a unique name.

However, in the main scene, all of my navigation is done through re-usable button instances which is why I do not understand why it is not working in the child mcs.

My main question is, shouldn't I be able to re-use instance names in a child mc? If so, then what am I doing wrong?

Declaring Stage Instances
Which would be the preferred method for declaring stage instances?

To leave the "Automatically declare stage instances" checkbox in the Publish>AS3 Settings unchecked and declare it in the class like so:


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

    public class PhotoLoader extends MovieClip {
       
        // Use this or check "Automatically declare stage instances" in AS3 prefs.
        public var uploaderButton:PhotoUploader;
       
        private var fileFilter:FileFilter = new FileFilter ("Images","*.jpg;*.jpeg;*.gif;*.png");
        private var fileReference:FileReference = new FileReference;

        public function PhotoLoader () {
            getChildByName("uploaderButton").buttonMode = true;
            getChildByName("uploaderButton").addEventListener (MouseEvent.CLICK, uploadImage);
        }
        public function uploadImage (event:MouseEvent):void {
            fileReference.browse ([fileFilter]);

        }
    }
}

Or to use the "Automatically declare stage instances" checkbox and omit the declaration in the class like so:


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

    public class PhotoLoader extends MovieClip {
       
        private var fileFilter:FileFilter = new FileFilter ("Images","*.jpg;*.jpeg;*.gif;*.png");
        private var fileReference:FileReference = new FileReference;

        public function PhotoLoader () {
            getChildByName("uploaderButton").buttonMode = true;
            getChildByName("uploaderButton").addEventListener (MouseEvent.CLICK, uploadImage);
        }
        public function uploadImage (event:MouseEvent):void {
            fileReference.browse ([fileFilter]);

        }
    }
}

It would seem that the latter is easier as long as you didn't overlap variable and instance names. What would be the best practice? I don't want to start developing bad habits as I did with AS2.

Trouble Accessing Variables
Hi, I'm trying to send this string to Flash and the only way I can get anything to show up in the text field is to refer to "this" in the LoadVars. Otherwise, I get an "undefined". Not sure what I am doing wrong but I'm sure it's something simple.










Attach Code

///PHP
$query = 'SELECT * FROM my_employees';
$result = $db->query($query);
$total = $result->num_rows;
//echo $total;
global $str_all;
while ($row = $result->fetch_assoc()){
$str = urlencode($row['emp_fname'])." ";
$str .= urlencode($row['emp_lname'])." ";
$str .= urlencode($row['emp_ext'])." ";
$str .= "<a href='mailto:";
$str .= urlencode($row['emp_email'])."@mydomain.com'>";
$str .= urlencode($row['emp_email'])."@mydomain.com</a> ";
$str .= urlencode($row['emp_title'])." ";
$str .= "
";
$str_all .= $str;
//echo $str;
}
$toflash = '' ;
$toflash .= 'str='.$str_all;
echo $toflash;
//Flash
var lvGetList:LoadVars = new LoadVars();
lvGetList.onLoad = function(success:Boolean){
if(success){
_root.textHolder_mc.phoneList_txt.htmlText=this;
}else{
trace("error loading/parsing LoadVars");
}
}
lvGetList.load("http://0.0.0.0/qry_2_employees.php");

Accessing The Stage
How can I access the stage from an fla's document class? my god how I'm getting frustrated.

Accessing The Stage?
In my FLA I have a document class called Main.as. I created a class called MainNav.as and imported it into the Main.as class. I am having trouble trying to access stage.stageWidth value from the MainNav.as class. Anytime I try to get the value I get an error.

The only way I got it to work was, if I created an empty MC in my library then attached the MainNav class to the MC. When I do it that way I can no longer import it into the Main.as class, unless I want it to error out.

What I am trying to do is convert my AS 2 site to AS 3. I have it set up in AS 2 so that the site loads the xml then dispatches an event to animate the nav. In AS 3 I am not sure if I can do it that way if I link the MC to the class and not import into my Main class.

Thanks

Accessing The Stage?
So am I the only one who's really pissed off by this "don't have access to stage" -thing??? I am trying to create a flash website that contains several external classes that I've created. In those classes I can't type stage.stageWidth for example. The only plase where I can access the stage is the document class. But this is totally not very useful. Now that I've created a preloader (a separate swf), the preloader is the only place where I can access the stage!!! This would be OK if I had a fixed sized flash site but I want it to be 100 % in width and height also when user resizes his browser window. There must be a way to fix this because I know people out there have created sites with AS3.0 that have been built using OOP structure and their stage is resizable.

Accessing A Mc In Stage
hi
I created a sprite called "pt" and traced it using "trace(stage.pt)", but it returns "access of possibly undefined property pt through a reference blah blah....."

so I removed the stage part and it still returns a similar error, what should I use then?
this AS3 thing is way more complicated than I thought....

Accessing The Stage
I don't understand how objects on the stage (created in the Flash IDE) can be accessed.

In AS2, it was simple, just use _root or this.stage. In AS3, this appears not to be the case.

Here is an example class


Code:
package johnbailey{
import flash.display.MovieClip;
import flash.display.Stage;
import fl.transitions.Tween;
import fl.transitions.easing.*;

public class myStageClass{

private var _stage:MovieClip = null;

public function myStageClass(thestage:MovieClip){
this._stage = thestage;
var myTween:Tween = new Tween(this._stage.box_MC, "x", Elastic.easeOut, 0, 50, 3, true)
}
}
}
NOTE: box_MC is on the fla's stage



ANSWER sort of

See above
Then just put this in the fla with an mc instance of box_MC

import johnbailey.myStageClass;
var startIt = new myStageClass(this);

Script Initialisation Of Stage Instances
is it necessary to manually set the instances on the stage to their initialised state (eg, tint, alpha..) rather than just dropping them onto their positions and initialising them via script with onLoad or something?

I've tried to use onLoad for a stage instance like so and there's no effect
code:
//this script is on the frame that the instance first appears
instance_mc.onLoad = function(){
this._alpha = 0;
};


also tried this method, what happened during testing was that instance_mc stayed at _alpha=0
code:
//this script is on the frame that the instance first appears
instance_mc._alpha = 0;
instance_mc.onEnterFrame = function(){
this._alpha +=5;
if(this._alpha >= 100){
delete this.onEnterFrame;
}
};

[MX04] Load MC Into MC (stage Instances)
Is anyone familiar with a way in which to load an MC (background) on the stage, into another MC (backgroundHolder) on the stage?

Normally I'd use a linkage identifier, however in this instance I want a large MC asset to load at a particular point in the movie rather than export it in the first frame. I figured that one of the following methods should work, but sadly not ...

_root.backgroundHolder.attachMovie("background");
_root.backgroundHolder.loadMovie("background","bac kground",1);

I'd really appreciate anyone with a working method.

ASDoc With Stage Instances Not Declared...
I was wondering if there is a way to get ASDoc to work even though stage instances aren't explicitly declared in classes (i.e. "Automatically declare stage instances" is checked off in the Actionscript 3.0 settings); currently ASDoc won't render any documentation due to compiling errors (can't find property, etc)...Anyone have any work around?
Thanx in advance

Check Instances On Stage With Loop
I have a bunch of items on the stage (in this case its checkboxes) all named b_1 b_2 b_3 and so on.

What I want to do is use a loop to check them all to see if any are ticked.


Code:
var checkTimer:Timer = new Timer(100);
var interval1:Number = 1;

checkTimer.addEventListener(TimerEvent.TIMER, checkBoxes);

function checkBoxes(event:TimerEvent):void
{
if ('b_' + interval1.selected == true)
{
trace('is selected');
interval1 ++;
}
else
{
trace("isn't selected");
interval1 ++;
}
}

checkTimer.start();
I've used a timer so I could check them at regular intervals.

I know the condition in the if statement is wrong, but I hope you know what I'm trying to do.

They all start with b_ and end with a number, so I thought there should be a way to tell flash to look for instances starting with b_ and fill in the rest with a variable.

Targetting Stage Instances From External .as
How can I target an instance on my stage from external .as that is not the document class?

Let's say I have a combobox on the stage called cmbList as the instance name. I have a document class set on the FLA to Videoplaylist. If I try to do anything in code from this Videoplaylist.as with cmbList it works fine.

There are sections of the code I want to break out into external classes. So now I have a new class called CustomWebServices that extends Sprite. When I try to reference cmbList I get errors that I am trying to access an undefined property. If I try to declare it I get that it has a null value.

Multiple Instances Of A Symbol On One Stage
Hello,

I have multiple instances of a symbol on one stage. I want to add a function that is called when the user clicks the individual symbol. Just as a test I want to trace the instance's name.

No matter what I try, it will call the function for all instances of the symbol when only one symbol is clicked.

For example, I have instances s0 - s3 of a symbol and this code:


Code:
for(var i:Number = 0; i < 4; i++)
this["s" + i].onMouseUp = function() { trace( this._name ); }
When s0 is clicked, the following is printed:
s0
s1
s2
s3

It does the same thing if I create a class extending MovieClip with the onMouseUp function and using that class for the symbol.

Please help, thank you.
-
Lath

Passing Arguments To Instances On-stage
Hey,

If you place an instance of a class on stage in the IDE, is there any way to pass arguments to it? Say if the class looks like
ActionScript Code:
public function myClass(i:int,n:Number,s:String)
, I'd like to write in these args from the IDE somehow. I'm working on a platform game and it'd be infinitely easier to do this on stage rather than place every single object via actionscript.

Thanks in advance!

Dispatching Events Of Instances On The Stage
hi

When I add one instance of my class on the stage, event's handler perform function inside this instance. But when I add more instances on the stage all the functions performs only in the last added instance, even if event dispatched in other instance. How should I declare event handlers in my class to make them perform functions inside that instance where event was dispatched?





























Edited: 03/25/2008 at 02:03:44 PM by Anergy

In A Loop, Set Color Of Stage Instances
Hi,

I'm reading an XML file, receiving the hex value, then setting the color of an object on the stage using Tweener. There are 88 objects (keys on a keyboard).

Here's the code I'm using:

Code:
function ParseColors(bookInput:XML):void {
var i:Number = 1

while (i < 88) {

var k = (bookInput.key.k.text()[i]); //this is the number of the key
var khex= (bookInput.key.hex.blank.text()[i]);

var theKey = "k"+i;

trace(theKey);
trace(khex);

Tweener.addTween(theKey, {_color:khex, time:2});

i++;

}

}
The traces show everything correctly, but Tweener throws errors when it tries to set each key to it's corresponding colors.

The keys are on the stage with instance names k1,k2,k3,k4, etc.

I think I'm missing something silly, can anyone help out?

For Loop - Trouble Accessing Arrays
Okay, bare with me,

I have two arrays, xArray holding x coordinates and yArray holding y coordinates.
A new coordinate is added to each array upon a button on (release).
Upon another button on (release) the variable 'clicked' is set to true and the speed variable is set to 10.
The idea being that when clicked = true, my movie clip 'scitter' rotates and moves to the first set of coordinates and then the next etc.

It doesn't, can anybody help?

I'm using the code below, the for loop should access the same position in
both arrays as they are the same length.

if (clicked) {

for (n=0; n<_root.scitter.xArray.length; n++) {

{// calculate angle to next target
gotoSpotX = _root.scitter.xArray[n] ;
gotoSpotY = _root.scitter.yArray[n] ;
delta_x = _x-gotoSpotX;
delta_y = _y-gotoSpotY;
targetRotation = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
_rotation = targetRotation;

}// move to clicked spot
if (Math.sqrt((delta_x*delta_x)+(delta_y*delta_y))>sp eed) {
_y -= speed*Math.cos(_rotation*(Math.PI/180));
_x += speed*Math.sin(_rotation*(Math.PI/180));
}
}
}

I originally had this obtain it's initial x,y coordinates from a mouse click as per the MX example and it worked fine. So I should be able to substitute these coordinates with my coordinates from the array, I assume that there is something wrong with the way I have written the loop.

Any help would be most appreciated, (pulling my hair out).

Trouble Accessing CuePoint Properties
Hi, Im using Flash CS3 and Actionscript 2.
I made an FLV with embedded Event Cuepoints which contain parameters. I want to have the cuepoints set a movie clips visibilty parameter. I named the parameter the same as the movie clips instance name and set the value to true.
Here is my code which works.

var listenerObject:Object = new Object();

function cpinfo(cp: Object) {
for (var paramName:String in cp.info.parameters){
if (cp.info.parameters[paramName] == "true"){
_root[paramName]._visible = true;
}
else {
_root[paramName]._visible = false;
}
}
trace (paramName);
trace (cp.info.parameters[paramName]);
}
myVideo.addEventListener("cuePoint", cpinfo);

Now what I want to do but cant get it to work is to not have to use the IF statement and just use this:
_root[paramName]._visible = cp.info.parameters[paramName];

For some reason the movie clip visibility is not being set to the parameter value using the above line..
The trace for the parameter value is showing the correct value. Is the way Im trying to access the parameter value incorrect? Any help would be appreciated.

rayz007

Trouble Accessing Cached Pages
Okay, when you visit a page, I set a variable of that page's name to equal "1," so that if you revisit that page, you won't see the preloader again, and the cached page will reload instantly.

Well, it works most of the time, but sometimes the previously viewed page doesn't show all it's elements. I'm trying to think of a work around. Like maybe lopading each page into its own movie clip and moving the movieclip off the stage when it's not being viewed.

But I'm open to suggestions.

here's the site: http://www.breenglindmeyer.com/index2.html

Skip the intro and clik the buttons in the top right and then on the main stage and you'll seee what I am trying to do.


thanks

Trouble Accessing Sound Duration - Help
I can't seem to access the sound duration value in my code, I am not sure what I am doing wrong.


ActionScript Code:
var directory:String = "Voices/";var noOfSongs:Number = 100;var aSongs:Array = [];var currIndex:Number = 0;for (var i = 1; i<=noOfSongs; i++) {aSongs.push("v"+i+".mp3");}VSound = new Sound(Voice1_mc);function playSound(songIndex:Number):Void {VSound.loadSound(directory+aSongs[songIndex], true);VSound.setVolume(VSound.getVolume()+50);trace(VSound.duration);VSound.start(0, 0);}VSound.onSoundComplete = function() {currIndex++;if (currIndex == aSongs.length) {currIndex = 0;}playSound(currIndex);};playSound(currIndex);

Trouble Accessing Button Within A MovieClip
Hello All,

Rundown ... One scene and all AS code resides within the 'actions' layer on the 'main' timeline. I've encountered several issues but I have no option but to deal with one at a time.

At this point I'm simply trying to access one button ... that for the life of me cannot figure out why I can't.

instance name: cont_back_mc
inside movie clip: cont_mc


Quote:




target paths I'm using:
----------------------------------------------------------

cont_mc.cont_back_mc.onRelease = function (){cont_mc.gotoAndPlay("_off");}

cont_mc.cont_back_mc.onRollOver = function (){cont_mc.cont_back_mcgotoAndStop("_over");}

cont_mc.cont_back_mc.onRollOut = function (){cont_mc.cont_back_mc.gotoAndStop(1);}
----------------------------------------------------------




I haven't a clue as to why the button will not ... could anyone lend a hand?

I would really appreciate it. Thanks in advance.

Accessing The Buttons On The Stage
Hi

I am facing a problem while i am trying to access the Button object on the stage...

I am writing the function I am using....

function progressHandler(event:VideoProgressEvent):void
{
var bl = Math.round(event.bytesLoaded/1000);
var bt = Math.round(event.bytesTotal/1000);
var time:Number = (bl/bt)*display.metadata.duration;
var cc = display.findNearestCuePoint(time)
if (cc != null){
trace(cc.name+"_btn");// This gives me the instance name of the
// button. Now, how can I play with the
// properties of the button. 'this' here
// gives the main
// timeline...
}
}

Thanks for any help that can be provided...

Vicky

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