Hello everybuddy,
Cracking site, I normally don’t post but have read and learned much from here thanks to all the posters!
I’m struggling with AS3 at the moment, forcing myself to take an OO approach and slowly getting there… However I’m now stuck…
My project is a dynamically generated web page, getting pics and data from xml files.
I have a button class that creates buttons based on an xml file, this is in its own class file(buttons.as) which is called from my document class.
The document class also creates a bunch of thumbnails using (screen.as), the thumbnails are placed in an MC called thumbs (which created by the document class).
What I need now is a way of linking my button class to the thumbs MC, so that when I click a button my thumbs MC is tweened using my dotween function.
when I run my project i get an errror from my buttons.as --> 1120: Access of undefined property thumbs.
I guess what i’m asking is how to reference an MC created in one class, from another seperate class. I thought that by setting it to public this would be possible but its not working…
Here is my code:
//Document.as
package {
import flash.display.MovieClip;
public class Document extends MovieClip {
public var thumbs = new MovieClip;
public var butArr = new Array;
public var screen1:screen;
public var thumbArr = new Array;
public function Document() {
//add buttons
for (var i:uint = 0; i < 10; i++) {
button* = new buttons(i);
addChild(button*);
}
//add thumb container
this.addChild(thumbs);
//addthumbs
for (var i:uint = 0; i < 10; i++) {
var thumbleft:uint=140+i*320;
thumbArr* = new screen(thumbleft,275,i,320,240,"thumb");
thumbs.addChild(thumbArr*);
}
screen1 = new screen(140,35,1,640,240,"home");
addChild(screen1);
}
}
}
//buttons.as
package {
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.text.*;
import flash.filters.GlowFilter;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
public class buttons extends MovieClip {
public var num:uint=1;
public var myXML:XML;
public var thisText =thisText;
public var thisID:uint = thisID;
public function buttons(thisID) {
this.num=thisID;
getXML();
}
public function getXML() {
var urXML:URLRequest;
var ulXML:URLLoader;
urXML=new URLRequest("buttons.xml");
ulXML = new URLLoader(urXML);
ulXML.addEventListener(Event.COMPLETE, xmlLoaded);
ulXML.load(urXML);
}
public function xmlLoaded(event:Event) {
myXML = XML(event.target.data);
var xmlID=thisID-1;
thisText=myXML.butTitle[this.num];
makeButton(thisText);
}
public function makeButton(thisText) {
var myTextField:TextField=new TextField;
// Here we add the new textfield instance to the stage with addchild()
addChild(myTextField);
// Here we define some properties for our text field, starting with giving it some text to contain.
// A width, x and y coordinates.
myTextField.text=thisText;
myTextField.width=120;
//myTextField.height=50;
myTextField.multiline = true;
myTextField.wordWrap = true;
myTextField.x=15;
myTextField.y=this.num*50+50;
// Here are some great properties to define, first one is to make sure the text is not selectable, then adding a border.
myTextField.selectable=false;
//myTextField.border=true;
// This last property for our textfield is to make it autosize with the text, aligning to the left.
//myTextField.autoSize=TextFieldAutoSize.LEFT;
//This is the section for our text styling, first we create a TextFormat instance naming it myFormat
var myFormat:TextFormat=new TextFormat;
// Giving the format a hex decimal color code
myFormat.color=0xFFFFFF;
// Adding some bigger text size
myFormat.size=16;
myFormat.font="SkandiaDisplay";
// Last text style is to make it italic.
//myFormat.italic=true;
// Now the most important thing for the textformat, we need to add it to the myTextField with setTextFormat.
myTextField.setTextFormat(myFormat);
this.addEventListener(MouseEvent.CLICK,changePage);
this.addEventListener(MouseEvent.MOUSE_OVER,mouseover);
this.addEventListener(MouseEvent.MOUSE_OUT,mouseout);
}
function mouseover(evt:MouseEvent):void {
var glow:GlowFilter = new GlowFilter(0xFFFFFF,0.5,5,5);
this.filters=[glow];
}
function mouseout(evt:MouseEvent):void {
this.filters=[];
}
function changePage(evt:MouseEvent):void {
var newPage:Number=evt.currentTarget.num;
trace(newPage);
//not working
//1120: Access of undefined property thumbs.
thumbs.dotween("x",700,460);
}
public function dotween(command,startVal, endVal) {
var myTween:Tween = new Tween(this,command, None.easeOut, 0, 1, 1, true);
}
}
}
Any help would be greatly appreciated!!!
Thanks in advance!