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




Calling An Object By Its .name



Im trying to call an object by its name property but its not working. I can see the names appear as children of menuCont. Is this not the way to address "we"?Attach Codevar indivMenuArr:Array = ["we", "prt", "br", "yt"];var menusXArr:Array = [0, 202, 404, 606];for (var i:Number=0; i < indivMenuArr.length; i++) {var indivMenuCont:MovieClip = new MovieClip();indivMenuCont.name = indivMenuArr[i];trace(indivMenuCont.name);menuCont.addChild(indivMenuCont);indivMenuCont.x = menusXArr[i];indivMenuCont.graphics.beginFill(0x009900);indivMenuCont.graphics.drawRect(0, 0, 100, 100);indivMenuCont.y = 0;}// this below does not work, but the name is part of the display list for menuContmenuCont.we.rotation = 270;



Adobe > ActionScript 3
Posted on: 06/05/2008 04:15:06 PM


View Complete Forum Thread with Replies

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

[CS3] Calling An Object From Another Class
I have two classes :
1- JigSaw (MAIN CLASS)
2-FlashCSS (.CSS LOADING HERE)

From JigSaw, i want to use the .css file loaded in an object called "stylesheet",witch is in a function called "completeListener", witch is inside a constructor named "FlaschCSS".

CompleteListener function is called when the.css file has loaded.


PHP Code:




package puzzle
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class JigSaw extends Sprite
    {

        var myTextField:TextField = new TextField;

        public function JigSaw ()
        {


            CreateScene ();
        }
        public function CreateScene ()
        {

            var myTextField:TextField = new TextField;
//HOW DO I CALL THE LOADED STYLE SHEET THATS IN THE STYLESHEET OBJECT?
myTextField.styleSheet=  ???

            myTextField.htmlText = "<p>Jig Saw Puzzle Game</p>";
            addChild (myTextField);


        }








This is the FLASH CSS CLASS :
// It loads an external css file, by itself it works fine.
//I just dont know how to call it from my main class.


PHP Code:




package puzzle
{
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    import flash.net.*;
    public class FlashCSS extends Sprite
    {
        public function FlashCSS ( )
        {
            
            var urlLoader:URLLoader = new URLLoader( );
            urlLoader.addEventListener (Event.COMPLETE, completeListener);
            urlLoader.load (new URLRequest("styles.css"));
        }
        private function completeListener (e:Event):void
        {
            var styleSheet:StyleSheet = new StyleSheet( );
            styleSheet.parseCSS (e.target.data);
        }
    }
}








Any tips or clues ?
Thks.

Calling Object Issue
Hi,
Can anyone assist me as to where i might be going wrong?
I am unable to call back the object into flash.
Here is my actionscript:

Code:
import mx.remoting.*;
import mx.remoting.debug.*;
import mx.rpc.*;

//The helpful Delegate for UI component event listeners
import mx.utils.Delegate;

var GATEWAY_URL:String = "http://localhost/flashservices/gateway.php"

var SERVICE_NAME:String = "pmpakContactsEditCompany"
var service:Service;

NetDebug.initialize();
//Create the service
service = new Service(GATEWAY_URL, null, SERVICE_NAME);

var pc:PendingCall = service.editCompany(company_id);
pc.responder = new RelayResponder(this, 'editCompany_Result', null);

editCompany_Result = function(data){
trace(data.pm_company_id);
}
and my NetDebug results:

Code:
DebugId: "0"
EventType: "Result"
MovieUrl: "file:///C|/wamp/www/graphlogik_flash/admin/contacts.swf"
Protocol: "http"
Source: "Client"
Time: 1159302714546
Date (object #1)
....."Wed Sep 27 06:31:54 GMT+1000 2006"
Result (object #2)
.....pm_company_address_1: ""
.....pm_company_id: "1"
.....pm_company_name: "Graphologik"
.....pm_company_type: "default"
Cheers

Calling A JavaScript Object
Hi Actionscriptpeople!

I have a little question and have a hard time figuring it out. I know i can call static functions with the ExternalInterface. But my problem resides in the fact that i need to call a function within a javascript object that may not exist at the time of execution.

What is needed is that i make a new object (ex : new JavaScriptCustomObject ) and then run a function within it.

So ideally this would translate to something like :

var jsObject = new JavaScriptCustomObject();
ExternalInterface.call(sjObject.customfunction);


I thank you for your help

Trouble Calling Last Object
I keep getting stuck in the mud on this. The short of the long if I would like my prevImage object to do something (in the ex. below I have the x prop. change to 0 - in the future I will have it fade in), then create a new object of the same type to replace it. I am getting the below error and Im not sure why. I have traced my vars and they check out to be correct.


Quote:




TypeError: Error #1009: Cannot access a property or method of a null object reference.
at BotMenu/downClick()





ActionScript Code:
var prevImage:LoadImg;
        var loadMyImg:LoadImg;
private function downClick(event:MouseEvent):void {
            trace(_mainTL,event.currentTarget.mainImg,event.currentTarget.mainImgBtnVar,event.currentTarget.uniqueName);
            _mainTL.caption_txt.text=event.currentTarget.cap;
            _mainTL.main_txt.text=event.currentTarget.mainImg;
            prevImage=loadMyImg;
            this.prevImage.x = 0;
            loadMyImg=new LoadImg(_mainTL,event.currentTarget.mainImg,event.currentTarget.mainImgBtnVar,event.currentTarget.uniqueName);
            //var loadMyImg:LoadImg=new LoadImg(_mainTL,event.currentTarget.mainImg,event.currentTarget.mainImgBtnVar,event.currentTarget.uniqueName);
        }

Calling Object From Library...
hi there...anybody know the script to call out an object to the stage from library? When something happen, close objectA on stage and bring out the objectB from library. using "TellTarget"?"UnloadMovie"?

Calling All Sound Object Experts
I'm having real problems with the following script. I'm trying to play all my sounds (about 30 or so) from a single button's release. The script was working fine until I got up to 'mySound9' at which point it stoppped working. I have tried using different sounds but these appear to be fine. I have also tried different extensions e.g 'mySoundB' but this does not seem to affect the problem.

Is there a simpler way to write these actions? or is Flash reaching it's limitation (or perhaps this is a bug!). Basically I just need to tell Flash to play these 30 odd sounds all at the same time.

Any helpers will be massively respected
Thanks people...

(here's my script)


on (release) {
mySound1 = new Sound (bass_1clip1);
mySound1.attachSound ("bass_1");
mySound1.start(0,100);
}
on (release) {
mySound2 = new Sound (bass_2clip1);
mySound2.attachSound ("bass_2");
mySound2.start(0,100);
}
on (release) {
mySound3 = new Sound (click_1clip1);
mySound3.attachSound ("click_1");
mySound3.start(0,100);
}
on (release) {
mySound4 = new Sound (click_2clip1);
mySound4.attachSound ("click_2");
mySound4.start(0,100);
}
on (release) {
mySound5 = new Sound (cowbell_1clip1);
mySound5.attachSound ("cowbell_1");
mySound5.start(0,100);
}
on (release) {
mySound6 = new Sound (cowbell_2clip1);
mySound6.attachSound ("cowbell_2");
mySound6.start(0,100);
}
on (release) {
mySound7 = new Sound (cowbell_3clip1);
mySound7.attachSound ("cowbell_3");
mySound7.start(0,100);
}
on (release) {
mySound8 = new Sound (key_A1clip1);
mySound8.attachSound ("key_A1");
mySound8.start(0,100);
}
on (release) {
mySound9 = new Sound (key_A2clip1);
mySound9.attachSound ("key_A2");
mySound9.start(0,100);
}
on (release) {
mySound10 = new Sound (key_A3clip1);
mySound10.attachSound ("key_A3");
mySound10.start(0,100);
}

((Any script after the 'mySound8' paragraph has no affect!))

Get Calling Clip/Object Of New Class?
Is it possible, when creating a new member of a class, to know what object (specifically what movieclip) made the request to create the member? (Much like arguments.caller in function objects).

Example: I have a class called Ball(targetClip), and I'm passing a target clip that I want the Ball object to be created in. Thus, myBall=new Ball(_root.BallHolderClip);. Now let's say I leave the targetClip blank. myBall=new Ball() . When this happens, I want to create the Ball in whatever movieclip contains that code. How can I find out what that movieClip is? I was hoping "this" or "this._parent" called from the class extended as a movieclip might work, but it still just points to the class object itself.

That's the gist of it. And yes, I know I can always say myBall=new Ball(this) as a fallback; what I'm really looking for is a way for the CLASS to know who's calling it, without being explicitly told. Is this even possible?

Maybe a better way of phrasing this is that I'd like to have my Class change it's behavior depending on who or what actually instantiated it, without explicity passing the instantiator. Make sense? Bad OOP practice? Impossible? Simple?

Calling A Method Of The Owner Of An Object
Here's what I have set up (note, this isn't my actual code, just a quick illustration):

Class1

ActionScript Code:
var actions:MovieClip = new Actions();

function Class1():void
{
      //does stuff
}

function iWantToCallThis():void
{
     //does stuff
}

Main .as file:

ActionScript Code:
var class1:MovieClip = new Class1();
var class2:MovieClip = new Class2();

{
      class2.takesClass1(class1);
}


Class2

ActionScript Code:
function class2():void
{
}

function takesClass1(class1:MovieClip):void
{
      //takes the actions instance from class 1:
      addChild(class1.actions);
}

Class Actions:

ActionScript Code:
(extends class1)

function Actions():void
{
     //now i want to call "class1.iWantToCallThis" from from here, even though this is the child of Class2
}

So, if I try to get the parent of the actions instance from within the Action class, it's Class 2 (because that's where I added the child at), so I can't do MovieClip(parent).method();.

What I want to do is call iWantToCallThis from within the actions instance after it is added as a child of class2.

Anyone help?

Calling Flash Object In Webpage
i have a flash swf file
it works when opened from flash iie the data is displayed when we play the movie
but when called in webpage no data appears
the swf file size is hardly 700 bytes
can anybody help me

Error Calling Methhod On NPO Object
Has anyone seen this error when using SetVariable? It seems to be random.

Calling Function From Object Method
Hi everybody.

I have created a class that does some calculation for me each 2 seconds.

I have the following in the class, i am creating an Object then assign an interval to it that call a method of the object as follow:


ActionScript Code:
function xTest(Id){
 
  this['xA'+Id] = new Object();
  var xB = this['xA'+Id];
  xB.Counter=0;
  xB.Limit =10;
  xB.method = function (xB){
     with(xB){ // with this object (xB)
       if(Counter>=Limit){
         clearInterval(xB.aInterval); // clear Interval, works
         xDeleteObj(xB); // call the function that delete the Object
       }else{
         Counter++;
       }
     }
  }
  xB.aInterval = setInterval(xB.method,1000,xB);
 
}
 
function xDeleteObj(xB){
   trace('Entering deleting function');
   delete xB;
}


The problem is that when i am in the method of the object, i am unable to call the xDeleteObj function to delete the object. I have tested with test function and when i am in the interval, i am unable to call any functions.

Can someone tell me what i do wrong or how can i call a fucntion from the object method.

thx

Calling A Function When Loading Ashared Object
I have four buttons that set different colour schemes to the site. The code on the button is like this, the only difference between the buttons is the colours fed into the 'colour' array.:

on (release) {
colour = ['0xCCA68C', '0x663300', '0x996633', '0xCCA68C', '0xCC9933', '0x1234cc', '0x1111BB', '0xFFFFFF', '0xFFFFFF', '0x996633'];
for (i=0, j=0; i<9, j<9; i++, j++) {
newcolor(clip[i], colour[j]);
}
}


I would like to add a line of code to the button, so that the function call is stored in the SO (with the button's parameters). This way when the user returns, the function call is run and the colour scheme he last chose is loaded. Although the above code is not found in the root timeline, it does work when loaded into the root timeline

Internal Object Loading Xml And Calling Another Function Afterwards - PLEASE HELP
I have a MC object set up basically like this:

#initclip
function myMC (){
//variables for the mc
}

myMC.prototype.initialize = function (){
this.getXML();
}

myMC.prototype.getXML = function (){
myXML = new XML ();
myXML.onLoad = this.parseXML;
myXML.load ("http://myURL.php");
myXML.ignorewhite = true;
}

myMC.prototype.parseXML = function (success){
if (success){
this.anotherFunction();
}else{
trace ("Error loading XML");
}
}

myMC.prototype.anotherFunction = function (){
//code i am trying to get to execute after the xml has loaded
}
Object.registerClass ("myMC", myMC);
#endinitclip

I HAVE ALSO ATTACHED A TESTER MOVIE WITH THE XML TO SEE FURTHER WHAT I HAVE DONE AND AM DOING.

I am calling myMC.initialize () from the root time line. It hits that function, calls the getXML function and hits the parseXML function fine! My problem is that I cannot get the 'anotherFunction' function to execute upon the successful load of the XML from the parseXML function.

Any suggestions as to why this is doing what its doing.

One thing i did get to work is that in the parseXML function I can call up like this... _root.myMC.anotherFunction() and it works. But I don't want to do this. 1) its sloppy 2) i can't guarantee the MC will always be at _root and called myMC. So this restricts me way too much.

PLEASE HELP!!!
Derek Neely
derek@mediaflux.com

Calling Listener Functions On The Event Object
Hi all --

How can I get an instance of a custom class to receive a custom event from the main document class and fire a listener function from the custom class? This is confusing to explain, so I imagine it's even harder to understand. Here's some code to help illustrate:


PHP Code:



_scrollBar2.addEventListener(MSPMain.CURRENT_SECTION_CHANGED, RoundedScrollBar2.doSomething);




The main document class is "MSPMain". "_scrollBar2" is an instance of the custom RoundedScrollBar2 class that extends Sprite. "CURRENT_SECTION_CHANGED" is a public static constant of the MSPMain class. "doSomething" is a public static method of the RoundedScrollBar2 class.

I can test to make sure the event is actually being dispatched by moving the doSomething function to the main document class and temporarily changing the code above to read like this...


PHP Code:



addEventListener(MSPMain.CURRENT_SECTION_CHANGED, doSomething);




... but ideally I want the event to trigger the listener function in the RoundedScrollBar2 class.

Is there something wrong with my syntax, or am I trying to oversimplify a more complex issue?

Thanks!

Calling Loadmovie From Within A Movieclip Class Object
Okay, i'm having a weird problem which i'm hoping someone will be able to shed some light on.

I've written a class - Symbol - that extends the movieclip class, and I have an object in the library which is asigned to this class.

Various instances of this object are created on the stage (by another class).

The object then loads an external swf, using loadmovie, into itself. At this point, the object loses it's functions and properties... it's no longer the Symbol class i've defined. In particular, I have set mousover properties which no longer work, but like I said, its seems to no longer be a Symbol object.

To get round that, I tried deploying an empty movie clip inside the object of my Symbol class, and loading the external swf into that instead so as not to overide the object itself, but the same thing happens.

I have even ensured that I place the empty clip that the SWF loads into beneath another layer with an alpha of 0, within the Symbol object. This in an attempt to ensure that something of the object itself is above the external swf so its mousover functionality can execute, but no joy.

Can anyone help me? So much thanks in advance (and more to come).

Problems Calling Object Functions From _root
Hi.

My code is posted below.
I have several instances of an mc_button on my stage. I wish to control the buttons from the _root by calling functions. However I am struggling to get my functiosn to work correctly. (you can see btn6 littered throughout as I try to test a single button before getting all 9 to work).

Am I doing something glaringly wrong?
Why doesn't a function call from _root, such as:
_root.btn6.beginRandom();
work?

Any help would be appreciated.

Kind Regards,
Cassandra.

mc_button has the following functions:

Code:
beginRandom = function(){
movementController.removeMovieClip();
this.attachMovie("c_rndmove", "movementController", 1);
};

moveDirectTo = function(target_x, target_y){
movementController.removeMovieClip();
this.attachMovie("c_directmove", "movementController", 1);
movementController.moveDirectTo(target_x, target_y);
};

btn_c1.onRelease = function(){
_root.buttonPressed(5);
};
The root has the following code:

Code:
NUMBUTTONS = 9;

btnArray = new Array("btn1","btn2",...
contentArray = new Array("content1","content2","...
homeTIGHT_x = new Array(500,533,514,...
homeTIGHT_y = new Array(2,27,34,...
homeEXT_x = new Array(505,370,365,...
homeEXT_y = new Array(230,50,70,50,...


_root.btn6.beginRandom();

buttonPressed = function(num){
for (jj=0; jj < NUMBUTTONS; jj++) {
//stop random on all buttons
//all buttons move to home
//_root.btnArray[jj].moveDirectTo(homeTIGHT_x[jj], homeTIGHT_y[jj]);
_root.btn6.moveDirectTo(homeTIGHT_x[jj], homeTIGHT_y[jj]);
_root.btn6.beginRandom();
}

}

Calling Listener Functions On The Event Object
Hi all --

How can I get an instance of a custom class to receive a custom event from the main document class and fire a listener function from the custom class? This is confusing to explain, so I imagine it's even harder to understand. Here's some code to help illustrate:


ActionScript Code:
_scrollBar2.addEventListener(MSPMain.CURRENT_SECTION_CHANGED, RoundedScrollBar2.doSomething);

The main document class is "MSPMain". "_scrollBar2" is an instance of the custom RoundedScrollBar2 class that extends Sprite. "CURRENT_SECTION_CHANGED" is a public static constant of the MSPMain class. "doSomething" is a public static method of the RoundedScrollBar2 class.

I can test to make sure the event is actually being dispatched by moving the doSomething function to the main document class and temporarily changing the code above to read like this...


ActionScript Code:
addEventListener(MSPMain.CURRENT_SECTION_CHANGED, doSomething);

... but ideally I want the event to trigger the listener function in the RoundedScrollBar2 class.

Is there something wrong with my syntax, or am I trying to oversimplify a more complex issue?

Thanks!

Calling Object Methods From Inside Listeners...
Hello guys,

Not sure if it is a common issue, but I've been looking into it for a couple of hours now, but not able to pull anything out. The thing is I'm learning classes in AS2 and was just experimenting with extending MovieClipLoader class to make another class with better functionality that will be more useful to me. Here is the class definition I've laid out...


ActionScript Code:
class ImageLoader extends MovieClipLoader {
    private var illist:Object;
   
    private var holder_mc:MovieClip;
   
    private var _progress:Number;

    public function ImageLoader(s:MovieClip) {
       
        super();

        illist = new Object();
       
        holder_mc = s.createEmptyMovieClip("holder_mc", s.getNextHighestDepth());
    }
   
    public function loadimg(path:String){
       
        this.loadClip(path, holder_mc);
       
        illist.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
            trace(Math.round((bytesLoaded/bytesTotal)*100));
            _progress = Math.round((bytesLoaded/bytesTotal)*100);
            somefunc();
        };
        this.addListener(illist);
    }
   
    public function somefunc(){
        trace(_progress);
    }
}

When the loadimg() method is called, the path of the image passed as argument is loaded into the holder_mc movieClip that was created in the constructor. Below is a code of how I'm calling it from flash...


ActionScript Code:
var my_il:ImageLoader = new ImageLoader(this);

my_il.loadimg("1.jpg", this);

Now, the image loads properly but, I'm not able to call the 'somefunc()' function of the class that I'm calling from the onLoadProgress event. I do understand that the issue is about scope of the function with respect to the object that I'm calling from, but is there a way to call the function from inside that 'onLoadProgress' event?

Any help is really appreciated...Thanks.

Calling Methods From Local Shared Object
Hi,

I have got a little problem with saving data in local shared objects. I want to store objects of a special class I made. This works without any problem, but when I try to call a method in this class, nothing happens.
I searched this forum and googled a lot, but didn't find anything.

Maybe I describe the problem a bit better. The objects are used to save different propertys. Some of them are also objects of custom classes. The whole structure is very complicated. I need only one method, that is used to copy the content of the object into another object. (I don't need a pointer that points to the local shared object, I need a copy that can be changed independantly)

I could write a global method that reads all the propertys of the objects, but this would be very difficult and take a lot of time, as the structure is so complicated.

Is there any easy way to copy a custom object from a local shared object?

Calling Object Names And Variables Dynamicly?
Im kind of new to flash, and Im having trouble figuring out how to do this.


Say I have some sort of user-input that will give me a number, for example the number 3.
Then I want to call one of many movieClips i've previously created, according to that input.
So I would like to dynamicly call ex. myMovieClip3._visible = true.

What I cant figure out is how to construct a way to call myMovieClip(x) and its variables.


Thanks for reading!

Watch Object Properties And Get Calling Function?
I want to watch a property of an object to see when it changes, like so:


ActionScript Code:
var myObject:Object = new Object();myObject.xDirection = -1;function objectWatcher(prop, oldVal, newVal) {    trace ("xDirection is being changed from " + oldVal + " to " + newVal);    return newVal;}myObject.watch("xDirection", objectWatcher);myObject.xDirection = 22;


This works as expected.

But if the value of the property being watched, is changed within a function, is there a way to tell which function that was?

EG:


ActionScript Code:
var myObject:Object = new Object();myObject.xDirection = -1;function objectWatcher(prop, oldVal, newVal) {    trace ("xDirection is being changed from " + oldVal + " to " + newVal);    //I want to be able to output something like this:    trace("It was changed by " + NAME_OF_CALLING_FUNCTION);    return newVal;}function changeTheValue():Void {    myObject.xDirection = 22; }myObject.watch("xDirection", objectWatcher);changeTheValue();


Any help would be appreciated. Thanks.

Calling The Document Class From Other Object Instances
I have a Flash CS3 fla with a document class specified. Lots of other classes exist, too, and they're directly or indirectly spawned from the document class. I can pass "this" as a parameter from the document class to instances I create so that those child objects have a reference to the document class. But it seems to me that I shouldn't need to do that. That all children must "know" what the document class is.

Is that true? If it is, how to I talk to the document class from other object instances in my project? In other words, what's the syntax to reference a method in the document class?

Using Varibles To Define An Object When Calling A User Function
I'm working on a booking system and using flash as the front end , and need to update loads of cells at once . The easiest way that i thought of doing this would be to have one cell call the update function in the next cell but in order to do that i need to define the object name with a varible.

e.g

varible.update();

Could anyone suggest how to do it or suggest an easier way of updateing all the cells.

Shared Object Arrays - More Efficient Than Calling Several Data.variables?
Lost in the concept...

I am using several shared objects..

defined as :
so.data.a = 1;
so.data.b = 2;
so.data.c = 5;....etc. (never ending list of real values)

Is it more efficient to define the shared object as an array, as far as memory is concerned?

I know it's more easier for me to read the array, but I was wondering if there's a difference in the processing of data per say.

thanks

Error #1009 (null Object Reference) When Calling A Function
Hello! I'm having a hard time because of an "Error #1009: Cannot access a property or method of a null object reference" I get everytime I try to run my Flash-movie. I've attached the code that is contained in frame 1.

The function bringUpEasyQuestion is defined on frame 2, along with other functions that are defined there. Now when I test the movie, I get this message:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MES_fla::MainTimeline/bringUpEasyQuestion()
at MES_fla::MainTimeline/frame1()

I've read that the Error1009-message means that you are trying to access something that isn't there yet. And indeed, the bringUpEasyQuestion-function accesses objects that exist only on frame 2. But the first line of the function bringUpEasyQuestion is gotoAndStop(2);. The curious thing is that it works when i put the last line of the code in frame one (the function call bringUpEasyQuestion(0);) on the first line of frame 2. Why is that? Shouldn't all the objects on frame 2 be instantiated/born/whatever with the command gotoAndStop(2);?

Thanks in advance

P.S.: It might be of interest that I'm quite new to Flash...







Attach Code

var EASY_CORRECT_ANSWERS:Vector.<int> = Vector.<int>([1, 0, 1, 3, 1, 0, 3, 1, 2, 3]);
var easyCorrectSound:EasyRichtig = new EasyRichtig();
var easyCurrentQuestion:int = 0;
var hardCurrentQuestion:int = 0;

var easySelectedAnswer:int;

var easyAntwortengitter:Vector.<MovieClip> = new Vector.<MovieClip>(4);
var Antwortknöpfe:Vector.<MovieClip> = new Vector.<MovieClip>(4);
var easyFrage:MovieClip = new MovieClip();
var easyAntworten:Vector.<MovieClip> = new Vector.<MovieClip>(4);

bringUpEasyQuestion(0);

Sound Object - Doesn't Work When Calling Previous Timeline Frame?
Hi everyone.

I'm having this problem that is more theory rather than code and I'm wondering if anyone has had the same issue.

I'm using the sound object in flash to script all my sounds. Everything is fine, exept - when there is a sound playing (looping for example), and my MAIN timeline is called to a previous frame - the sounds just stop working.

Does the sound object not allow sounds to play when called to a previous keyframe?

Wondering if someone has had this problem.

Thanks alot!

Calling A Function, External To The Calling Class
hello to everyone, who looks at this post
So there's a class, that needs to call/access an external function.
'External' (imho) in this case would be any function, declared outside of the class.
How is it possible to:
1) call a function declared in the main timeline.
2) call a function in another class (i suppose, the only way of doing it is by importing the class having this function into the calling class?)

How Is This Done (Drag Object Anywhere Return To Origin), Object Follow Mouse On Lock
Both on same site,

1/. how did he do the dragable discs to the left of the introduction text?

2/. how did he make it so when you roll over a menu link, an object follows it underneath, but also stays there until you roll over the next?

Thanks

Making An Object Dissapear Once A Moving Object Makes Contact With It
Hello there,

Im in need of some help. Basically I need a code which will make an object disappear once another moving object hits it (MovieClips controlled by AS)

For example, a bullet comes out of the gun and hits a can which makes the can disappear as soon as the bullet hits it.

Is it something to do with the "intersects" function? I've been trying to solve it all day and cant do it

Please help.

Whats It Called When You Drag An Object And Want The Object To Continue Moving
i am trying to work out how to make a draggable movie clip/button continue to move in the same direction as the drag guides it...hmmmm does this make sense???? what is this function / behaviour called.... i have looked at many many drag tutorials but at present have only managed to find drag and drop type onces with target positions.... also does any one know if it is possible assign multiple drag points.

regards....

Video Object - Call To Load And Listener Object Not Working
i've got a video object within a movieclip who's full path i put in a var called 'video'. here's my code, it appears that the video object is not loading my stream and/or i'm not getting the listener object to work properly... everything does trace out good as far as vars, rtmp address, etc... grrr!!!


Code:
//function to load the stream in the vid object
_global.loadVid=function(vidFile){
trace("this is path to vidObj: "+video);
trace("loadVid function var passed: "+vidFile);
var listenerObject:Object = new Object();
listenerObject.ready=function(eventObject:Object):Void{
//video loaded, do this
video.removeEventListener("ready", listenerObject);
_root.container.vidPanel.gotoAndPlay("tovideo");
trace("video is loaded, proceeding to video play state");
};
video.addEventListener("ready", listenerObject);
var nV:String=rtmpURL+vidFile;
video.load(nV, true);
trace("video: "+rtmpURL+vidFile+" should be loading");
}

How'd U Make An Object Snap 2 Its Original Pos On An Object Thats Moved?
I'm working on a school project using Flash mx that needs a scrolling inventory. I know how to get an object to snap back to its original position from a drag, but how would you get it to snap back to its original position on an object that has moved? ie. On a scrolling menu?

//script to have a spanner remove a head and snap back to position if it doesn’t touch the head on release:

//attach to object

onClipEvent (load) {
spanx = _root.spanner._x;
spany = _root.spanner._y;
}


//action inside clip

on (press) {
startDrag(this,true);
}

on (release, releaseOutside) {

if (this.hitTest(_root.dismantle.head) & _root.head_switch=="hollow") {
_root.spanner.gotoAndPlay(2);
_root.dismantle.head.gotoAndPlay(2);
this._y = 185;
_root.airbrush._x= _root.airbrush.airbx;
_root.airbrush._y= _root.airbrush.airby;
}

else {
_root.spanner.gotoAndStop(1);
this._x = spanx;
this._y = spany;
this.gotoAndStop(2);

}

stopDrag();

}

how would i script a scrolling inventory from which I can drag and drop objects that snap back to the same pos in the inventory even tho its moved? You can see the inventory on the right of the attached jpeg.

Papervision Acsess Individual Object Within .dae File/Object
Hello,

The following code loads a .dae file into a new DAE() Object i am trying to acsess a specific child within de Object called "Loja1" (one of many) with var storeisplayObject3D = holder.getChildByName("Loja1"); to individually rotate it etc... but with no sucsess.

Does anyone know how this is acomplished ?

Thanks in Advance.

files at : http://www.kiyoshii.com/transfer/src.zip


Code:
package {

import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

public class Pulitzer3d extends Sprite {
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
public var scene:Scene3D;
public var camera:Camera3D;
public var dae:DAE;
public var cm:ColorMaterial;
public var holder:DisplayObject3D;
public var cameraBtn:BtnCamera;

public function Pulitzer3d() {
init();
}
private function init() {
//basic scene stuff
viewport = new Viewport3D(1024, 768, true,true);

addChild(viewport);

renderer = new BasicRenderEngine();

scene = new Scene3D();

camera = new Camera3D(holder, 15, 100);

camera.zoom = 500;

camera.z = -50;

//COLOR MATERIAL
cm = new ColorMaterial(0xFF0099, .85, true);

//DAE
dae = new DAE();

dae.load("floor_rename.dae", new MaterialsList( { all:cm } ));

holder = new DisplayObject3D();
holder.addChild(dae);

holder.rotationX = 90;
holder.rotationY = 45;

scene.addChild(holder);

var store:DisplayObject3D = holder.getChildByName("Loja1");

trace("DAE : " + store);

stage.addEventListener(Event.ENTER_FRAME, renderStuff);

}
private function renderStuff(e:Event) {
renderer.renderScene(scene,camera,viewport,true);
//camera.x += (((stage.mouseX-(stage.stageWidth * .5))*2)-camera.x )*.05;
//camera.y += (((stage.mouseY-(stage.stageHeight*.5))*2)-camera.y )*.05;
}
}
}

Web Service Param Is An Object Inside And Array Which Is An Object
Howdy. This is my first time on this forum, and I hope I get more help here than some of the other forums. I'll try to explain my dillema as simply as possible.

I have a webservice. I am calling a method 'InsertSlide'. That method requires and object as the paramater.
the object shcema looks like this:

Object
-SlideID (integer)
-Name (integer)
-SlideTypeID (integer)
-Hits (integer)
-LocationID (integer)
-SwfFileName (integer)
-SlideDataCollection (Array)
- -N (Object)
- - -Label
- - -Value

I hope that makes sense, all I'm trying to get at, is there is an object with an array as a property, that array is populated with an object and it has properties.

I recieve that same ojbect from the webservice fine, but when I send that object like that to the Webservice it does not fully populate my databases, unfortunatly I did not write the webservice.

Is it possible that the problem is the webservice? or flash?

Thanks for any help!
- Kiwi

Targeting Object Properties Inside PopUp Object
In my project I am creating a window using the PopUpManager. The symbol used to create that window has several objects.

For the sake of discussion we'll discuss the object message_txt inside myWindow.

How do I reference message_txt.text from actionscript after the object is dynamically created?

Gravity Issue? Object Slides Through Another Object Instead Of Sitting On Top Of It
Hello!

I have a file where two objects fall from the top of the stage and bounce and then eventually stop (using gravity and hit test).

You can grab the objects (a ball and a box --- each has a button symbol n the movie clip) and toss them and they bounce off each other and off the 4 sides of the stage.

The issue is when one of the objects is dropped directly on top of the other object, after it stops bouncing, it slides down until it hits the bottom of the stage (in this case, the box slides down in front of the ball, and the ball slides down in back of the box).

Is this because the gravity is pulling the object down to the bottom of the stage even though there's another object in its way?

How can I fix this so that the objects will still bounce off each other, and when dropped directly on top of each other object will stop instead of oozing through it (sorry, this is the best way I can describe it ?

I've attached 2 files (Fla 8 and Fla mx 2004).

-------- here is the gravity code on the first frame:


PHP Code:



var gravity:Number = 1.2;
var restitution:Number = 0.6;
var friction:Number = 0.9;

stop(); 




-------- here is the code on the ball


PHP Code:



onClipEvent(load) {
    var dragging:Boolean = false;
    var vel:Object = { x: 0, y: 0 };
    var pos:Object = { x: _x, y: _y };
    var old:Object = { x: _x, y: _y };
    var radius:Number = this._width / 2;
    var movie:Object = { width: 400, height: 300 };
}

onClipEvent(enterFrame){    
    if( !dragging ) {
        vel.y += _root.gravity;
        
        pos.x += vel.x;
        pos.y += vel.y;

        if( pos.y + radius > movie.height ) {
            pos.y = movie.height - radius;
            vel.y *= -_root.restitution;
            vel.x *= _root.friction;
        }
        
        if( pos.x + radius > movie.width ) {
            pos.x = movie.width - radius;
            vel.x *= -_root.restitution;
        }
        
        if( pos.x < radius ) {
            pos.x = radius;
            vel.x *= -_root.restitution;
        }
        
        _x = pos.x;
        _y = pos.y;
        
    } else {
        old.x = pos.x;
        old.y = pos.y;
        pos.x = _x;
        pos.y = _y;
        
        vel.x = ( pos.x - old.x ) / 2;
        vel.y = ( pos.y - old.y ) / 2;        
    }    

    
if(this.hitTest(_root.box)) {
        trace("hit");
        // ball and box are colliding, so lets reverse their movements.
        vel.x *= -1;
        vel.y *= -1;
        _root.box.vel.x*=-1;
        _root.box.vel.y*=-1;
        
        /*  these actions could be made more realistic by determining the precise
        position of the ball relative to the box during the collision, for instance,
        determine if the right side is colliding with the left side, so only reverse
        the x velocity, instead of both.  */
    }
    
    //this prevents the ball from leaving the upper extreme of the stage
    if (this._y < 0) {
            vel.y*=-1;
    }  





-------- here is the code on the button inside the ball (so you can drag and release the ball)


PHP Code:



on(press){
    startDrag(this,false,16,16,384,284);
    dragging = true;
}
on(release, releaseOutside){
    stopDrag();
    dragging = false;





-------- here is the code on the box


PHP Code:



onClipEvent(load) {
    var dragging:Boolean = false;
    var vel:Object = { x: 0, y: 0 };
    var pos:Object = { x: _x, y: _y };
    var old:Object = { x: _x, y: _y };
    var radius:Number = this._width / 2;
    var movie:Object = { width: 400, height: 300 };
}

onClipEvent(enterFrame){    
    if( !dragging ) {
        vel.y += _root.gravity;
        
        pos.x += vel.x;
        pos.y += vel.y;

        if( pos.y + radius > movie.height ) {
            pos.y = movie.height - radius;
            vel.y *= -_root.restitution;
            vel.x *= _root.friction;
        }
        
        if( pos.x + radius > movie.width ) {
            pos.x = movie.width - radius;
            vel.x *= -_root.restitution;
        }
        
        if( pos.x < radius ) {
            pos.x = radius;
            vel.x *= -_root.restitution;
        }
        
        _x = pos.x;
        _y = pos.y;
        
    } else {
        old.x = pos.x;
        old.y = pos.y;
        pos.x = _x;
        pos.y = _y;
        
        vel.x = ( pos.x - old.x ) / 2;
        vel.y = ( pos.y - old.y ) / 2;        
    }    





-------- here is the code on the button inside the box (so you can drag and release the box)


PHP Code:



on(press){
    startDrag(this,false,16,16,384,284);
    dragging = true;
}
on(release, releaseOutside){
    stopDrag();
    dragging = false;






I appreciate any help anyone can give me to fix this issue, I don't understand enough yet about how these objects are interacting to fix this --- but I hope to learn from you brilliant Kirupians!) Thanks!

Hondo311

Tween Class To Move An Object Called From Within The Object
I have a custom class that I want to move with the Tween Class
I am calling the Tween constructor from within that class but when I pass the keyword "this" as the object of that constructor , it doesnt move at all the code is as follow


PHP Code:



package{import fl.transitions.Tween;import flash.display.MovieClip;public class PortViewer extends MovieClip{var _twn:Tween;public function PortViewer(){    _twn = new Tween(this, "y", None.easeNone, 0, 100, 2, true);}}} 




how do I reference the object from within itself is there another keyword?
There are no errors it just doesnt move

Thank you Kirupa forums

AS3 - Papervision Acsess Individual Object Within .dae File/Object
Hello,

The following code loads a .dae file into a new DAE() Object i am trying to acsess a specific child within de Object called "Loja1" (one of many) with var store: DisplayObject3D = holder.getChildByName("Loja1"); to individually rotate it etc... but with no sucsess.

Does anyone know how this is acomplished ?

Thanks in Advance.

files at : http://www.kiyoshii.com/transfer/src.zip


Code:
package {

import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

public class Pulitzer3d extends Sprite {
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
public var scene:Scene3D;
public var camera:Camera3D;
public var dae:DAE;
public var cm:ColorMaterial;
public var holder:DisplayObject3D;
public var cameraBtn:BtnCamera;

public function Pulitzer3d() {
init();
}
private function init() {
//basic scene stuff
viewport = new Viewport3D(1024, 768, true,true);

addChild(viewport);

renderer = new BasicRenderEngine();

scene = new Scene3D();

camera = new Camera3D(holder, 15, 100);

camera.zoom = 500;

camera.z = -50;

//COLOR MATERIAL
cm = new ColorMaterial(0xFF0099, .85, true);

//DAE
dae = new DAE();

dae.load("floor_rename.dae", new MaterialsList( { all:cm } ));

holder = new DisplayObject3D();
holder.addChild(dae);

holder.rotationX = 90;
holder.rotationY = 45;

scene.addChild(holder);

var store:DisplayObject3D = holder.getChildByName("Loja1");

trace("DAE : " + store);

stage.addEventListener(Event.ENTER_FRAME, renderStuff);

}
private function renderStuff(e:Event) {
renderer.renderScene(scene,camera,viewport,true);
//camera.x += (((stage.mouseX-(stage.stageWidth * .5))*2)-camera.x )*.05;
//camera.y += (((stage.mouseY-(stage.stageHeight*.5))*2)-camera.y )*.05;
}
}
}

Papervision Acsess Individual Object Within .dae File/Object
Hello,

The following code loads a .dae file into a new DAE() Object i am trying to acsess a specific child within de Object called "Loja1" (one of many) with var store:DisplayObject3D = holder.getChildByName("Loja1"); to individually rotate it etc... but with no sucsess.

Does anyone know how this is acomplished ?

Thanks in Advance.

files at : http://www.kiyoshii.com/transfer/src.zip

Code:

package {

import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

public class Pulitzer3d extends Sprite {
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
public var scene:Scene3D;
public var camera:Camera3D;
public var dae:DAE;
public var cm:ColorMaterial;
public var holder:DisplayObject3D;
public var cameraBtn:BtnCamera;

public function Pulitzer3d() {
init();
}
private function init() {
//basic scene stuff
viewport = new Viewport3D(1024, 768, true,true);

addChild(viewport);

renderer = new BasicRenderEngine();

scene = new Scene3D();

camera = new Camera3D(holder, 15, 100);

camera.zoom = 500;

camera.z = -50;

//COLOR MATERIAL
cm = new ColorMaterial(0xFF0099, .85, true);

//DAE
dae = new DAE();

dae.load("floor_rename.dae", new MaterialsList( { all:cm } ));

holder = new DisplayObject3D();
holder.addChild(dae);

holder.rotationX = 90;
holder.rotationY = 45;

scene.addChild(holder);

var store:DisplayObject3D = holder.getChildByName("Loja1");

trace("DAE : " + store);

stage.addEventListener(Event.ENTER_FRAME, renderStuff);

}
private function renderStuff(e:Event) {
renderer.renderScene(scene,camera,viewport,true);
//camera.x += (((stage.mouseX-(stage.stageWidth * .5))*2)-camera.x )*.05;
//camera.y += (((stage.mouseY-(stage.stageHeight*.5))*2)-camera.y )*.05;
}
}
}

Position Object By Center Of Other Object And Stage Left...?
lol! :lol:

what i mean is i have an object (mc = main_logo) that centers itself upon load:

main_logo._x = Stage.width / 2;
main_logo._y = Stage.height / 2;

and i want another object (mc = helmet) to always load up 2/3rds to the left (x axis) of main_logo's center (counting left to right, 2/3rds between main_logos center and stage left border) and 200 pixels above (y axis) main_logo's center.

i know i keep asking these things and i'm not trying to have you all do every little thing for me, i am trying to learn this! it's just that my brain operates differently and i have to assimalate information by what i'm trying to accomplish...

thanks!

How Do I Move An Object In The Opposite Direction Of Another Object?
Hello,

This seems like it should be easy but for some reason I'm having trouble making it happen... any help would be greatly appreciated.

I know how to set the Y position and get the Y position of objects, but what I'm trying to do is have one object move exactly opposite to another.

The first object is draggable. If it is dragged up 10 pixels, then I want the other object to move down 10 pixels.

Any suggestions?

Thank you!!

Janet

Uploading A Flash Object -- Speed Of Object
If I insert an object into a plain web page -- nothing else on it, in order for that flash object to function, Q: the only thing I upload to the web (besides the page of course) is just the flash object file???

When I saved the file, I see I have two: a Shockwave Flash Object, and a Swish Movie.

So I'm confused on how I saved these files and why I ended up with two?

Are there different methods of saving them? a correct way and an incorrect way?

And how do you take one of these objects/movies and condense it so it still works the same but loads quickly?

pj

Problem Controlling Object From Another Object (scroll Bar)
First time posting here so hope I don't screw up here

Hope I can exlpain my problem and make sense. What I am trying to do control an object from another object. It's a scroll bar moving a block of text. Each line is going to be a button trigering a loadmovie() in a main flash movie. I have a working version of the scroller in a different movie, but in this case the scroller is within another instance. I'm guessing that my instance references are messed up but I can't figure out which ones. I used this tutorial to create this scroller: http://www.flashcircle.com/display.php?storyid=40

Here's a link to the fla:
http://www.httpworkshop.com/navigation.fla

Any help will be greatly appreciated.

Problem Rotating An Object Relating To Another Object...
Hi everyone...

I'm pretty much a newbie, and, naturally, stumped. If anyone can help me out, i would really appreciate it...

I have a lollipop-type object; (it has line/stem that attaches to a circle, fixed to the top of one end).

I want to rotate the object 180 degrees and have it pivot on the end opposite the circle (so the end with the circle appears to swing in an arc). At all times, the circle and the stem must seem to be joined as if they were one solid object. So far, no problem.

However, durning the arc, the stem must shrink in size an x amount. The stems' rotation point must remain fixed; it can't appear to move. The circle must remain it's original size, but still be attached to the stem, thus, the circle's position should gradually be closing up the space left by the shrinking stem at the same time the circle is moving through the arc. And i cannot figure out how to make this work!

To make the rotation work so far, I set the registration pt for the stem at the base of the stem (the pivot pt for it's rotation), set the registration pt for the circle also at the base of the stem (so they would share the same pivot point) and moved the circle to where it would set in relation to the stem. Then for both, i made _rotation = x, and on the stems' enterframe, i added 1 to x for both mcs.

(Also, to complicate the issue, at the beginning of the animation, the stem needs _xscale from 0 to 100, at which point it attaches the circle to it's tip; thus, the necessity of creating two movie clips: one for the stem, one for the circle.)

Thanks again for the help...

[F8] Flash Object To Display On Top Of An Activex Object
I’m having a problem getting a flash object (menu) to display on top of an activex object. Any ideas?

Making One Object Move Towards Another Object In Flash 8?
Hi, I need help on making one object move towards another object at a set speed, in Flash Professional 8.
So far I can get one object to move to another one but only doing a fraction of the distance at a time, as with this code:

PHP Code:



onClipEvent (enterFrame) {
    var xspd = (this._parent.redsquare._x - this._x) * .1;
    var yspd = (this._parent.redsquare._y - this._y) * .1;
    this._x += xspd;
    this._y += yspd;





How can I make it so it moves with a set speed? Anyone able to help?

Convert Object To Strongly Typed Object
I have the following function which serializes my plain obj:Object to custom:SomeObject.

It works great, but if I have ArrayCollection in the Object it would not convert it to my custom object and instead it will just avoid it.

Any help is appreciated...

Here is my code:


Code:
public static function objectToInstance( object:Object, clazz:Class ):*
{
var bytes:ByteArray = new ByteArray();

bytes.objectEncoding = ObjectEncoding.AMF0;

// Find the objects and byetArray.writeObject them, adding in the
// class configuration variable name -- essentially, we're constructing
// and AMF packet here that contains the class information so that
// we can simplly byteArray.readObject the sucker for the translation

// Write out the bytes of the original object
var objBytes:ByteArray = new ByteArray();
objBytes.objectEncoding = ObjectEncoding.AMF0;
objBytes.writeObject( object );

// Register all of the classes so they can be decoded via AMF
var typeInfo:XML = describeType( clazz );
var fullyQualifiedName:String = typeInfo.@name.toString().replace( /::/, "." );
registerClassAlias( fullyQualifiedName, clazz );

// Write the new object information starting with the class information
var len:int = fullyQualifiedName.length;
bytes.writeByte( 0x10 ); // 0x10 is AMF0 for "typed object (class instance)"
bytes.writeUTF( fullyQualifiedName );
// After the class name is set up, write the rest of the object
bytes.writeBytes( objBytes, 1 );

// Read in the object with the class property added and return that
bytes.position = 0;

// This generates some ReferenceErrors of the object being passed in
// has properties that aren't in the class instance, and generates TypeErrors
// when property values cannot be converted to correct values (such as false
// being the value, when it needs to be a Date instead). However, these
// errors are not thrown at runtime (and only appear in trace ouput when
// debugging), so a try/catch block isn't necessary. I'm not sure if this
// classifies as a bug or not... but I wanted to explain why if you debug
// you might seem some TypeError or ReferenceError items appear.
var result:* = bytes.readObject();
return result;
}

Convert A Video Object To A Bitmapdata Object
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.media.Camera;
import flash.media.Video;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;



public class CameraExample extends Sprite {

private var video:Video;
private var _bitmapData:BitmapData;
private var _bitmapDataDue:BitmapData;
private var mybitmap:BitmapData;

public function CameraExample() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

var camera:Camera = Camera.getCamera();

if (camera != null) {
camera.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
video = new Video(camera.width * 2, camera.height * 2);
video.attachCamera(camera);

addChild(video);

_bitmapData = new BitmapData(video.width , video.height, false);

_bitmapData.draw(video);

var _bitmapDataDisplay:Bitmap = new Bitmap(_bitmapData);
_bitmapDataDisplay.x= camera.width * 2;

addChild(_bitmapDataDisplay);


}

what's wrong with this?

thank yooou

[AS3] XMLDefinition() - XML To Object (object Definitions And Hierarchies In XML)
XMLDefinition is a function that translates XML into ActionScript object definitions. It works a lot like Flex but translates definitions at runtime. As a runtime translater, its limited (no scripting etc) but still flexible in what it can be used to create.

Attached is the class and a simple Flash CS3 example. Below is some documentation. I'll try to include a page with a live demonstration when I get a chance (and if I feel confident that the kinks have been ironed out).


Doc (from the AS file):
XMLDefinition()


Code:
public function XMLDefinition(xml:XML, targetParent:Object = null):Object
Creates an object (typically a display object) based on the definition outlined by the XML. Each XML element represents the object to be made. If that object's definition is in a pacakge, that element will need to be in a namespace whose uri matches that package. The hierarchy of the object created will match the hierarchy of the XML where display objects will be added as children to the display objects. Attributes are used to define properties. If a name attribute is defined, that name will also be used as a property name in the parent to store a reference to the child. If the parent is not a display object container or the child is not a display object and a name attribute is not provided, the child element's index will be used; this is useful when defining arrays as name attributes are not needed.

There are 3 kinds of elements for special uses, each of which defined in the com.senocular.xml.XMLDefinition namespace. They are:
- property
- call
- arguments

The property element is used to access an existing property of an object. For example, you may want to reference the transform property of a MovieClip instance defined in XML rather than redefine it. In that case you would use the property element to access that property's existing value rather than provide a new value to be set for the MovieClip's transform property. This element uses one attribute, name, to determine the name of the property being accessed.

The call element is used to call methods within objects. Like the property element, it too uses the name attribute to identify the class member (in this case a method) to be accessed. This would be useful for calling drawing methods on a display object. Method arguments are handled through the arguments element.

The arguments element is used in combination with class definitions or method calls. For class definitions (elements representing class instances) the arguments element contains the arguments for that instance's constructor call. For method calls, the arguments element's children are used as arguments for that method. The definitions within an arguments block is scoped to the parent node of the arguments element so references to property in an arguments element will reference properties in the argument's parent object. One caveat concerning the arguments element is that you are limited to 10 or less arguments.

The following example creates a Sprite a line drawn in its graphics object and one Shape child object with the instance name "child":


Code:
var definition:XML =
<display:Sprite x="50" y="100"
xmlns:display="flash.display"
xmlns:def="com.senocular.xml.XMLDefinition">
<display:Shape name="child" />
<def:property name="graphics">
<def:call name="lineStyle">
<def:arguments>
<Number>1</Number>
<uint>0xFF0000</uint>
</def:arguments>
</def:call>
<def:call name="lineTo">
<def:arguments>
<Number>100</Number>
<Number>100</Number>
</def:arguments>
</def:call>
</def:property>
</display:Sprite>

var sprite:Sprite = XMLDefinition(definition);
Parameters:
xml - The xml to be parsed into an object.
targetParent - The object in which the generated object will be defined, either as a property or a child display object.

Returns:
A reference to the object created.

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