Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-12-2009, 03:38 PM   #1
Sam Gothman
Registered User
 
Join Date: Nov 2009
Posts: 6
Default Address sprite from within .as

Basically I guess it is a reference problem I do have. (1120: Access of undefined property images)

For an image gallery I also do have a few text sprites which may have to much text for one side to display. Therefore I do have a scrollbar placed next to the text which should be able to move my text sprite within its mask.

My .fla at one point adds an InfoText (InfoText.as, extends Sprite) to an already existing sprite "images".

imageHolderArray[i]=new InfoText (xmlName)
images.addChild(imageHolderArray[i])
imageHolderArray[i].name=xmlName;

The InfoText get's the name of an xml file, then starts to load this xml file, populates text fields with it, etc. Work fine!
If the heigth of my textContainer sprite (create in InfoText.as) is taller than the display height, InfoText.as adds a scrollbar (Scrollbar.as, extends)

var scrollbar = new Scrollbar (xmlName,size,height)
addChild(scrollbar)
scrollbar.name="scrollbarClass"

I pass on the xmlName to be able to address the correct sprite.

The scrollbar itself work fine (moving the slider), too, BUT I'm not able to move my text container.

I tried stuff like

Sprite(images.getChildByName(xmlName).textContaine r).y=posY

and so on. But even

images.visible=fasle

won't work from within Scrollbar.as. Usually it is a 1120: Access of undefined property images.

The target path displayed when I list all objects is as follows:

image=0 target="_level0.portfolio.images.EXHIBITIONS.scrol lbarClass.scrollbar

and for the textContainer

image=0 target="_level0.portfolio.images.EXHIBITIONS.textC ontainer

Exhibitions is an example of what may be the content of the xmlName.

So, how do I point my line of code responsible for moving the textContainer from within Scrollbar.as at the textContainer sprite? Running against a wall since the last 6 hours and couldn't find any proper tips on the web.

Any help is much appreciated.

Cheers!
Sam Gothman is offline   Reply With Quote
Old 11-12-2009, 03:41 PM   #2
zsolemolina
Member
 
Join Date: Apr 2008
Posts: 67
Default

post within "AS" to understand better
zsolemolina is offline   Reply With Quote
Old 11-12-2009, 04:03 PM   #3
Sam Gothman
Registered User
 
Join Date: Nov 2009
Posts: 6
Default

ActionScript Code:
package {     import flash.display.Sprite;     import fl.containers.UILoader;     import fl.controls.ScrollBar;     import fl.controls.UIScrollBar;     import flash.events.*;     import fl.events.ScrollEvent;     import flash.events.MouseEvent;     import flash.geom.*;     import flash.net.URLLoader;     import flash.net.URLRequest;     import flash.text.TextField;     import flash.text.TextFormat;     import flash.text.AntiAliasType;     import caurina.transitions.*;     public class InfoText extends Sprite {         [Embed(systemFont="standard 07_53",fontWeight="normal",fontName="StandardTextFont",mimeType="application/x-font")]         public static var StandardText:Class;//hooge 05_53                 //--------variables--------         private var infoText:TextField;         private var textFormatHeadlineActive:TextFormat;         private var textFormatHeadlinePassive:TextFormat;         private var textFormatBodyActive:TextFormat;         private var textFormatBodyPassive:TextFormat;         private var colorBackground:int;         private var colorHeadline:int;         private var colorBodyActive:int;         private var colorBodyPassive:int;         private var colorSliderActive:int;         private var colorSliderPassive:int;         private var textX:int;         private var textY:int;         private var textXOffset:int;         private var textYOffset:int;         private var textSizeX:int;         private var textSizeY:int;         private var chosenImage:Object;         private var xmlName:String;         //--------menu text button--------         public function InfoText(cB:uint,cH:uint,cA:uint,cP:uint,sA:uint,sP:uint,xS:uint,yS:uint,xml:String):void {             //--- draw background rectangle ---             var truncatedString:String=new String  ;             var truncatedSign:String=new String  ;             var truncatedLetters:String=new String  ;             //--- transfer variables ---             colorBackground=cB;             colorHeadline=cA;             colorBodyActive=cA;             colorBodyPassive=cP;             colorSliderActive=sA;             colorSliderPassive=sP;             textSizeX=xS;             textSizeY=yS;             xmlName=xml;             trace("Name: ",xmlName)             textX=0;             textY=0;             textXOffset=3;             textYOffset=3;             //             //--- text format headline ---             textFormatHeadlineActive=new TextFormat  ;             textFormatHeadlineActive.font="StandardTextFont";             textFormatHeadlineActive.bold=false;             textFormatHeadlineActive.color=colorHeadline;             textFormatHeadlineActive.size=16;             textFormatHeadlineActive.align="left";             //--- text format headline ---             textFormatHeadlinePassive=new TextFormat  ;             textFormatHeadlinePassive.font="StandardTextFont";             textFormatHeadlinePassive.bold=false;             textFormatHeadlinePassive.color=colorHeadline;             textFormatHeadlinePassive.size=16;             textFormatHeadlinePassive.align="left";             //--- text format body active ---             textFormatBodyActive=new TextFormat  ;             textFormatBodyActive.font="StandardTextFont";             textFormatBodyActive.bold=false;             textFormatBodyActive.color=colorBodyActive;             textFormatBodyActive.size=08;             textFormatBodyActive.size=08;             textFormatBodyActive.align="left";             //--- text format body passive ---             textFormatBodyPassive=new TextFormat  ;             textFormatBodyPassive.font="StandardTextFont";             textFormatBodyPassive.bold=false;             textFormatBodyPassive.color=colorBodyPassive;             textFormatBodyPassive.size=08;             textFormatBodyPassive.align="left";             //             //--- text container mask---             var textContainerMask:Sprite=new Sprite  ;             textContainerMask.graphics.beginFill(0xF00000,1);             textContainerMask.graphics.drawRect(0,0,1280,1024);             textContainerMask.graphics.endFill();             textContainerMask.y=textSizeY*3;             textContainerMask.width=751-15-3;             textContainerMask.height=471-textSizeY*3;             textContainerMask.name="textContainerMask";             addChild(textContainerMask);             //             //--- text container ---             var textContainer:Sprite=new Sprite  ;             textContainer.name="textContainer";             addChild(textContainer);             //--- mask text ---             textContainer.mask=textContainerMask;             //---             sliceString(xmlName);             //---             loadXml(truncatedString);             //--- process XML file ---             function loadXml(nameXml:String) {                 //--- load xml ---                 var urlRequest:URLRequest=new URLRequest("xml/"+nameXml+"Text.xml");                 var urlLoader:URLLoader=new URLLoader  ;                 urlLoader.addEventListener(Event.COMPLETE,processXml);                 urlLoader.load(urlRequest);             }             //--- process XML file ---             function processXml(event:Event):void {                 //---                 var infoTextArray:Array=new Array  ;                 var infoTextXml:XML=new XML  ;                 var columnAmount:Number=new Number  ;                 //---                 var columnName:String=new String  ;                 var textAmount:Number=new Number  ;                 var columnText:String=new String  ;                 //var xmlImageDetails:XMLList;                 infoTextXml.ignoreWhitespace=true;                 infoTextXml=XML(event.target.data);                 //--- headline text ---                 columnAmount=infoTextXml.headline.length();                 //--- loop columns ---                 for (var i:int=1; i<=columnAmount; i++) {                     textAmount=infoTextXml.headline[i-1].text.length();                     //--- loop headlines ---                     for (var j:int=1; j<=textAmount; j++) {                         columnText=infoTextXml.headline[i-1].text[j-1];                         sliceString(columnText);                         //--- text field ---                         infoText=new TextField  ;                         if (truncatedLetters=="Head") {                             infoText.defaultTextFormat=textFormatHeadlineActive;                             columnText=truncatedString;                         } else {                             infoText.defaultTextFormat=textFormatHeadlinePassive;                         }                         infoText.embedFonts=true;                         infoText.antiAliasType=AntiAliasType.NORMAL;                         infoText.selectable=true;                         infoText.text=String(columnText).toUpperCase();                         infoText.width=infoTextXml.column[i-1].width;                         infoText.height=textSizeY*3;                         infoText.x=textX+textXOffset;                         infoText.y=textSizeY*2*(j-1);                         //--- add text ---                         addChild(infoText);                         infoTextArray.push(infoText);                     }                     textX=textX+Number(infoTextXml.headline[i-1].width);                 }//--- body text ---                 textX=0;                 columnAmount=infoTextXml.column.length();                 //--- loop columns ---                 for (var k:int=1; k<=columnAmount; k++) {                     textAmount=infoTextXml.column[k-1].text.length();                     //--- loop text ---                     for (var l:int=1; l<=textAmount; l++) {                         columnText=infoTextXml.column[k-1].text[l-1];                         sliceString(columnText);                         //--- text field ---                         infoText=new TextField  ;                         if (truncatedLetters=="Head") {                             infoText.defaultTextFormat=textFormatBodyActive;                             columnText=truncatedString;                         } else {                             infoText.defaultTextFormat=textFormatBodyPassive;                         }                         infoText.embedFonts=true;                         infoText.antiAliasType=AntiAliasType.NORMAL;                         infoText.selectable=true;                         infoText.text=String(columnText).toUpperCase();                         infoText.width=infoTextXml.column[k-1].width;                         infoText.height=textSizeY;                         infoText.x=textX+textXOffset;                         infoText.y=textYOffset*textSizeY+textSizeY*(l-1);                         //--- add text ---                         textContainer.addChild(infoText);                         infoTextArray.push(infoText);                     }                     textX=textX+Number(infoTextXml.column[k-1].width);                 }             }             //--- slice string ---             function sliceString(thisString:String):void {                 var thisStringLength:Number=thisString.length;                 truncatedString=thisString.substring(0,thisStringLength-5);                 truncatedSign=thisString.charAt(thisStringLength-5);                 truncatedLetters=thisString.substring(thisStringLength-4,thisStringLength);             }             //var scrollbar:Object= new Object();         var scrollbar=new Scrollbar(xmlName,colorBodyActive,colorBodyPassive,colorSliderActive,colorSliderPassive);         addChild(scrollbar);         scrollbar.name="scrollbarClass";         }     } }
Sam Gothman is offline   Reply With Quote
Old 11-12-2009, 04:05 PM   #4
Sam Gothman
Registered User
 
Join Date: Nov 2009
Posts: 6
Default

ActionScript Code:
package {     import caurina.transitions.*;     import caurina.transitions.properties.ColorShortcuts;     ColorShortcuts.init();     import flash.display.*;     import flash.events.*;     import flash.geom.*;     public class Scrollbar extends Sprite {         //---         private var scrollbarYOffset:Number;         private var scrollbarX:Number;         private var scrollbarY:Number;         private var scrollbarWidth:Number;         private var scrollbarHeight:Number;         //---         private var scrollbarSliderOriginWidth:Number;         private var scrollbarSliderOriginHeight:Number;         private var scrollbarFrameWidth:Number;         //---         private var scrollbarSlidingArea:Number;         private var scrollbarSlidingDistanz:Number;         private var scrollbarSliderWidth:Number;         private var scrollbarSliderHeight:Number;         private var scrollbarSliderX:Number;         private var scrollbarSliderY:Number;         //---         private var colorFrameActive:int;         private var colorFramePassive:int;         private var colorSliderActive:int;         private var colorSliderPassive:int;         private var textXOffset:int;         private var textYOffset:int;         private var textX:int;         private var textY:int;         //---         private var referenceTextName:String;         //---         private var textContainer:MovieClip;         private var textContainerHeight:Number;         private var top:Number;         private var bottom:Number;         private var dragBot:Number;         private var range:Number;         private var ratio:Number;         private var sPos:Number;         private var sRect:Rectangle;         private var textContainerY:Number;         private var transitionKind:String;         private var transitionTime:Number;         private var isUp:Boolean;         private var isDown:Boolean;         private var scrollBuffer:Number;         public function Scrollbar(rT:String,fA:uint,fP:uint,sA:uint,sP:uint):void {             //---             referenceTextName=rT;             colorFrameActive=fA;             colorFramePassive=fP;             colorSliderActive=sA;             colorSliderPassive=sP;             placeScrollbar();             //initializeScrollbar();         }         //------------------------------------------------------------------------------------------------------------------------         //--- place scrollbar         //------------------------------------------------------------------------------------------------------------------------         function placeScrollbar():void {             //--- set variables ---             textYOffset=3;             scrollbarYOffset=textYOffset*11;             //---             scrollbarX=736;             scrollbarY=scrollbarYOffset;             scrollbarWidth=15;             scrollbarFrameWidth=4;             scrollbarHeight=471-scrollbarYOffset;             //             scrollbarSliderOriginWidth=15;             scrollbarSliderOriginHeight=471-scrollbarYOffset;             scrollbarSliderWidth=scrollbarWidth-scrollbarFrameWidth;             scrollbarSliderHeight=320;             scrollbarSliderX=458;             scrollbarSliderY=2;             scrollbarSlidingArea=scrollbarHeight-scrollbarFrameWidth;             scrollbarSlidingDistanz=scrollbarSlidingArea-scrollbarSliderHeight;             //--- draw sprites ---             var scrollbar:Sprite=new Sprite  ;             scrollbar.x=scrollbarX;             scrollbar.y=scrollbarY;             scrollbar.buttonMode=false;             scrollbar.name="scrollbar";             addChild(scrollbar);             //---             var scrollbarFrame:Sprite=new Sprite  ;             scrollbarFrame.graphics.lineStyle(1,colorFrameActive,1);             scrollbarFrame.graphics.beginFill(colorFrameActive,0);             scrollbarFrame.graphics.drawRect(0,0,scrollbarWidth,scrollbarHeight);             scrollbarFrame.graphics.endFill();             scrollbarFrame.x=0;             scrollbarFrame.y=0;             scrollbarFrame.width=scrollbarSliderOriginWidth;             scrollbarFrame.height=scrollbarSliderOriginHeight;             scrollbarFrame.buttonMode=false;             scrollbarFrame.name="scrollbarFrame";             scrollbar.addChild(scrollbarFrame);             //---             var scrollbarTrack:Rectangle=new Rectangle  ;             scrollbarTrack=new Rectangle(0,0,0,scrollbarSlidingDistanz);             //---             var scrollbarSliderOrigin:Sprite=new Sprite  ;             scrollbarSliderOrigin.x=+2;             scrollbarSliderOrigin.y=+2;             scrollbarSliderOrigin.buttonMode=false;             scrollbarSliderOrigin.name="scrollbarSliderOrigin";             scrollbar.addChild(scrollbarSliderOrigin);             //---             var scrollbarSlider:Sprite=new Sprite  ;             scrollbarSlider.graphics.beginFill(colorSliderPassive,1);             scrollbarSlider.graphics.drawRect(0,0,471,471);             scrollbarSlider.graphics.endFill();             scrollbarSlider.x=0;             scrollbarSlider.y=0;             scrollbarSlider.width=scrollbarSliderWidth;             scrollbarSlider.height=scrollbarSliderHeight;             scrollbarSlider.name="scrollbarSlider";             scrollbarSlider.addEventListener(MouseEvent.ROLL_OVER,onSliderRollOver);             scrollbarSlider.addEventListener(MouseEvent.ROLL_OUT,onSliderRollOut);             scrollbarSlider.addEventListener(MouseEvent.MOUSE_DOWN,dragScroll);             scrollbarSliderOrigin.addChild(scrollbarSlider);             //-------- on slider roll over --------             function onSliderRollOver(event:MouseEvent):void {                 Tweener.addTween(scrollbarSlider,{_color:colorSliderActive,time:.25,transition:"linear"});             }             //-------- on slider roll out --------             function onSliderRollOut(event:MouseEvent):void {                 Tweener.addTween(scrollbarSlider,{_color:colorSliderPassive,time:.25,transition:"linear"});             }             //             //------------------------------------------------------------------------------------------------------------------------             //--- run scrollbar             //------------------------------------------------------------------------------------------------------------------------             function initializeScrollbar():void {                 //---                 textX=0;                 textY=0;                 textXOffset=3;                 textYOffset=3;                 textContainerHeight=900;                 transitionKind="easeOutBack";                 transitionTime=2;                 scrollBuffer=1.5;                 top=scrollbarSlider.y;                 dragBot=scrollbarSlider.y+scrollbarSliderOriginHeight-scrollbarSlider.height;                 bottom=scrollbarSliderOriginHeight-scrollbarSlider.height/scrollBuffer;                 range=bottom-top;                 textContainerY=textContainer.y;                 }             //--- slider scrolling ---             function dragScroll(event:MouseEvent):void {                 scrollbarSlider.startDrag(false,scrollbarTrack);                 stage.addEventListener(MouseEvent.MOUSE_MOVE,moveScroll);                 stage.addEventListener(MouseEvent.MOUSE_UP,stopScroll);                 stage.addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheelHandler);             }             //--- mouse wheel scrolling ---             function mouseWheelHandler(event:MouseEvent):void {                 if (event.delta<0) {                     if (scrollbarSlider.y<dragBot) {                         scrollbarSlider.y-=event.delta*2;                         if (scrollbarSlider.y>dragBot) {                             scrollbarSlider.y=dragBot;                         }                         startScroll();                     }                 } else {                     if (scrollbarSlider.y>top) {                         scrollbarSlider.y-=event.delta*2;                         if (scrollbarSlider.y<top) {                             scrollbarSlider.y=top;                         }                         startScroll();                     }                 }             }             //--- stop scrolling ---             function stopScroll(event:MouseEvent=null):void {                 scrollbarSlider.stopDrag();                 stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveScroll);                 stage.removeEventListener(MouseEvent.MOUSE_UP,stopScroll);                 stage.removeEventListener(MouseEvent.MOUSE_WHEEL,mouseWheelHandler);             }             //---             function moveScroll(event:MouseEvent):void {                 startScroll();             }             //--- move text container ---             function startScroll():void {                 ratio=textContainerHeight-range/range;                 sPos=scrollbarSlider.y*ratio-textContainerY;                 Tweener.addTween(textContainer,{y:- sPos,time:transitionTime,transition:transitionKind});                 //Sprite(images.getChildByName(referenceTextName)).visible=false                 //images.visible=false                                 //TextField(Sprite(menus.getChildByName("menuTextButton"+k)).getChildByName("menuText")).text                 //Sprite(portfolio.images.getChildByName(referenceTextName)).getChildByName("menuText").text                 //trace("images",stage.images)                 trace("referenceTextName",referenceTextName)             }         }     } }
Sam Gothman is offline   Reply With Quote
Old 11-12-2009, 04:08 PM   #5
Sam Gothman
Registered User
 
Join Date: Nov 2009
Posts: 6
Default

Right now there might be a bit of extra code and some function which aren't called. Basically I'll cook it down later to the necessary code. Right now it's important that I'm able to address the textContainer within the InfoText class.

The info text class get's called like described in the initial text from the document class.

Cheers!

P.S.: The attempts to get hold of any sprites are at the very end of Scrollbar
Sam Gothman is offline   Reply With Quote
Old 11-12-2009, 05:33 PM   #6
Sam Gothman
Registered User
 
Join Date: Nov 2009
Posts: 6
Default

Is this a difficult thing to do? It took me some time with the help of somebody else to figure out how to address sprites in classes from within the main document. So this time it would be more or less vice versa. As _root doesn't work anymore, there needs to be some other way to get to the sprite in need, right?


As already listed the target path of the object is listed as follows: _level0.portfolio.images.EXHIBITIONS.textContainer


This problem killed really my day. So it would be great if I could go to bed with a calm mind, knowing that this bugger won't be around any longer by tomorrow.


Cheers!
Sam Gothman is offline   Reply With Quote
Old 11-13-2009, 10:39 AM   #7
Sam Gothman
Registered User
 
Join Date: Nov 2009
Posts: 6
Default

The only success in terms of referencing so far has been passing on "this" to the scrollbar.as. But that would effect the whole InfoText instance. So I included all the files which are necessary in my zip. So far everything works fine, as it doesn't try to change a bit of the textContainer right now. The line which will cause errors are marked with an //. There are actually two lines which will need to get hold off the text container. One requests the .y and the other one sets .y. Both are towards the end of the scrollbar.as

I'm really walking on my gums already as I lost all my teeth in the last 2 days trying to chew this problem away. So any help will be highly appreciated.



Cheers and thanks for any help!
Attached Files
File Type: zip TestPackageFlash.zip (481.4 KB, 45 views)
Sam Gothman is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:08 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.