Canvas.addChild() - objects overwritting eachother???

In Actionscript - I'm trying to us a Canvas object to paste
multiple objects such as textarea, ColumnChart, Legend, and Labels
using Canvas.addChild(objectname). I started by adding 2 textarea
objects and when I send the Canvas to the printer, the 2 textareas
are overlaying/overwriting each other. How do I add these objects
and have them appear sequential - one right after the other? What
am I missing here?
Here is the current code:
private function doPrint():void {
var pj:PrintJob = new PrintJob();
var pagesToPrint:uint = 0;
if (pj.start()) {
var myCanvas:Canvas = new Canvas();
myCanvas.setStyle('backgroundColor', '#FFFFFF');
myCanvas.height = 2000;
myCanvas.percentHeight = 100;
myCanvas.addChild(myPrintText1);
myCanvas.addChild(myPrintText2);
pj.addPage(myCanvas);
pj.send();
}

What are the x and y coords of the myPrintText1 and
myPrintText2 objects?
Adding children to a Canvas defaults to 0,0 unless the x / y
coords are set.

Similar Messages

  • Array in object overwrite problem

    Hi
    hope you can help me with this as i've already been using too much time solving it myself :)
    I got a Board class which have an ArrayList<ArrayList<Integer>> as attribute. The Board class is controlled from my service class. I need to create a lot of boards which all needs different ArrayList<ArrayList<Integer>> input, so i made a for loop which creates the Boards. The problem is however when i change the variable i used to create the object the values also change inside the object even though the create method have already been called. English isn't my native language so it's a bit hard to explain :) Please ask if there's something you don't understand.
    thanks in advance!
    I made a temporary solution by making a 3d arraylist so i won't have to overwrite any values but thats not rly a good solution as it's starting to give me problems elsewhere.
    the method that creates the boards is Service.importCSV()
    model.Board
    package model;
    import java.util.ArrayList;
    public class Board {
         private String controleNumber;
         private ArrayList<ArrayList<Integer>> numbers = new ArrayList<ArrayList<Integer>>();
         private ArrayList<ArrayList<Integer>> remainingNumbers = new ArrayList<ArrayList<Integer>>();
         public Board(String controlenumber, ArrayList<ArrayList<Integer>> numbers) {
              this.controleNumber = controlenumber;
              this.numbers = numbers;
              this.remainingNumbers = numbers;
         public String getControlenumber() {
              return controleNumber;
         public void setControlenumber(String controleNumber) {
              this.controleNumber = controleNumber;
         public ArrayList<ArrayList<Integer>> getNumbers() {
              return numbers;
         public void setNumbers(ArrayList<ArrayList<Integer>> numbers) {
              this.numbers = numbers;
         public void setRemainingNumbers(ArrayList<ArrayList<Integer>> remainingNumbers) {
              this.remainingNumbers = remainingNumbers;
         public ArrayList<ArrayList<Integer>> getRemainingNumbers() {
              return remainingNumbers;
         public String toString() {
              return String.valueOf(controleNumber);
    }service.Service
    package service;
    import gui.MainFrame;
    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import ramdao.BoardDao;
    import model.Board;
    public class Service {
         private static ArrayList<Integer> numbers = new ArrayList<Integer>();
         public static List<Board> getAllBoards() {
              return BoardDao.getAllBoards();
         public static Board createBoard(String controleNumber, ArrayList<ArrayList<Integer>> numbers) {
              Board board = new Board(controleNumber, numbers);
              BoardDao.store(board);
              return board;
         public static void deleteBoard(Board board) {
              BoardDao.remove(board);
         public static Board checkFor(int checkFor) {
              for(Board board : getAllBoards()) {
                   System.out.println(board.getRemainingNumbers());
                   for(ArrayList<Integer> row : board.getRemainingNumbers()) {
                        for(int i=0;i<row.size();i++) {
                             if(numbers.contains(row.get(i))) {
                                  row.remove(row.get(i));
                   if(checkFor==1) {
                        for(ArrayList<Integer> row : board.getRemainingNumbers()) {
                             if(row.size()==0) {
                                  return board;
                   else if(checkFor==2) {
                        if(board.getRemainingNumbers().get(0).size()==0 && board.getRemainingNumbers().get(1).size()==0) {
                             return board;
                        else if(board.getRemainingNumbers().get(0).size()==0 && board.getRemainingNumbers().get(2).size()==0) {
                             return board;
                        else if(board.getRemainingNumbers().get(1).size()==0 && board.getRemainingNumbers().get(2).size()==0) {
                             return board;
                   else if(checkFor==3) {
                        if(board.getRemainingNumbers().size()==0) {
                             return board;
                   System.out.println(board.getRemainingNumbers()  );
              return null;
         public static ArrayList<Integer> oneToGo(int rows, ArrayList<Integer> numbers) {
              //TO-DO
              return null;
         public static void importCSV(ArrayList<String> buff) {
              ArrayList<ArrayList<ArrayList<Integer>>> allNumbers = new ArrayList<ArrayList<ArrayList<Integer>>>();
              int line = 0;
              String controleNumber = "";
              String[] splitLine = new String[10];
              for(int i=0;i<buff.size();i++) {
                   //adds the split buff to splitLine
                   for(int q=0;q<buff.get(i).split(";").length;q++) {
                        if(buff.get(i).split(";")[q].equals(""))
                             splitLine[q]="0";
                        else
                             splitLine[q]=buff.get(i).split(";")[q];
                   if(line==0) {
                        allNumbers.add(new ArrayList<ArrayList<Integer>>());
                        ArrayList<Integer> row = new ArrayList<Integer>();
                        allNumbers.get(allNumbers.size()-1).add(row);
                        controleNumber=buff.get(i).split(";")[0];
                        for(int q=buff.get(i).split(";").length;q<10;q++) {
                             splitLine[q]="0";
                        for(int q=0;q<9;q++) {
                             row.add(Integer.valueOf(splitLine[q+1]));
                   else if(line==1) {
                        ArrayList<Integer> row = new ArrayList<Integer>();
                        allNumbers.get(allNumbers.size()-1).add(row);
                        for(int q=buff.get(i).split(";").length;q<9;q++) {
                             splitLine[q]="0";
                        for(int q=0;q<9;q++) {
                             row.add(Integer.valueOf(splitLine[q]));
                   else if(line==2) {
                        ArrayList<Integer> row = new ArrayList<Integer>();
                        allNumbers.get(allNumbers.size()-1).add(row);
                        for(int q=buff.get(i).split(";").length;q<9;q++) {
                             splitLine[q]="0";
                        for(int q=0;q<9;q++) {
                             row.add(Integer.valueOf(splitLine[q]));
                        createBoard(controleNumber, allNumbers.get(allNumbers.size()-1));
                        line=-1;
                   line++;
         public static ArrayList<String> readFile(File file) {
              FileInputStream fileInputStream = null;
              ArrayList<String> buff = new ArrayList<String>();
              String line;
              try {
                   fileInputStream = new FileInputStream(file);
                   BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
                   BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream));
                   while ((line = bufferedReader.readLine())!= null) {
                        buff.add(line);
              catch (IOException ex) {
                   Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
              finally {
                   try {
                        fileInputStream.close();
                   catch (IOException ex) {
                        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
              return buff;
         public static void addNumber(int number) {
              numbers.add(number);
         public static ArrayList<Integer> getNumbers() {
              return numbers;
    }

    Tried the code but it's full of compiletime errors. I changed it a little but still got
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
         board cannot be resolved
         row cannot be resolved
         line cannot be resolved
         board cannot be resolved
         board cannot be resolvedwith the following code
    public static void importCSV(ArrayList<String> buff) {
              ArrayList<ArrayList<ArrayList<Integer>>> allNumbers
              = new ArrayList<ArrayList<ArrayList<Integer>>>();
              String[] splitLine = new String[10];
              String controleNumber;
              for(int i=0;i<buff.size();i++) {
                   int line = i % 3;
                   // split the buffer into fields
                   String[] splitBuf = buff.get(i).split(";");
                   int start = 0;
                   if(line==0) { // new board
                        ArrayList<ArrayList<Integer>> board = new ArrayList<ArrayList<Integer>>();
                        controleNumber = splitBuf[0];
                        start = 1;
                   ArrayList<Integer> row = new ArrayList<Integer>();
                   // fill row from the buffer fields...
                   for(int b = start, last = start+9; b < last; b++) {
                        if(b >= splitBuf.length || splitBuf.length() == 0)
                             row.add(0);
                        else
                             row.add(Integer.valueOf(splitBuf[b]));
              }This is my main problem:createBoard(controleNumber, board);
         board.clear();
         row.clear();The board that i created using the createBord method doesn't hold any numbers because i cleared the arrays i used to create it *after* creating it.
    got my software construction teacher to help me today :)
    works!     public static void importCSV(ArrayList<String> buff) {
              ArrayList<ArrayList<Integer>> board = new ArrayList<ArrayList<Integer>>();
              ArrayList<Integer> row = new ArrayList<Integer>();
              String controleNumber = "";
              int line;
              for(int i=0;i<buff.size();i++) {
                   line = i % 3;
                   String[] splitBuf = buff.get(i).split(";");
                   int start = 0;
                   if(line==0) { // new board
                        board = new ArrayList<ArrayList<Integer>>();
                        controleNumber = splitBuf[0];
                        start = 1;
                   row = new ArrayList<Integer>();
                   // fill row from the buffer fields...
                   for(int b = start, last = start+9; b < last; b++) {
                        if(b >= splitBuf.length || splitBuf[b].length() == 0)
                             row.add(0);
                        else
                             row.add(Integer.valueOf(splitBuf[b]));
                   board.add(row);
                   if(line==2) {
                        createBoard(controleNumber, board);
         }Edited by: Briam on Apr 12, 2010 12:37 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help with public function (accessing to addchild object from other public function)

    Hi, i have below piece of my code AS3 (Flash CS4). I would like to get access to addchild Movie Clip object (ZoltyWjazdMC) in function two() which i created by addchild command in public function one(). I know it`s basic question but i can`t find answer for it. Anybody would help me with that?
    public function one():void
    var ZoltyWjazdMC:MovieClip = new MovieClip();
    this.addChild(ZoltyWjazdMC);
    ZoltyWjazdMC.addChild(assets.ZoltyWjazd.loader);
    this.setChildIndex(ZoltyWjazdMC,1);
    ZoltyWjazdMC.alpha = 0;
    ZoltyWjazdMC.visible = true;
    assets.ZielonyWjazd.alpha = 1;
    public function two():void
    ZoltyWjazdMC.alpha = 1;
    Do i need remove "this" and change it to "stage". Is it necessary?

    Define your variable var ZoltyWjazdMC:MovieClip outside of function one(). Currently ZoltyWjazdMC is local to function one() so that function two() does not understand what it is!

  • Canvas - Graphic object properties

    The problem is as following:
    I’ve got a form where objects are situated on two tab pages. A number of text_items are placed on rectangle graphic objects. My goal is to control visibility of those objects depending on certain conditions:
    With text items correctly works:
    QUANTITY_ID ITEM;
    QUANTITY_ID := find_item('PRODUCT.QUANTITY');
    set_item_property (QUANTITY_ID, visible, property_false);
    With graphics object I’m facing the problem with reaching the item:
    G_QUANTITY_ID ITEM;
    G_QUANTITY_ID := find_item('?????????????.G_QUANTITY');
    Placement of the object:
    Forms -> Canvases -> Tab Pages -> [Product] -> Graphics -> [G_QUANTITY]
    Where:
    [Product] – Name of the tab page
    [G_QUANTITY] – Rectangle graphic object
    I’ll appreciate any kind of help. Thanks in advance.

    Hello,
    There is no available built-in concerning the graphic objects displayed on the canvas. All you can do use another stacked canvas to show/hide the graphic objects located on it.
    Francois

  • Howto bind objects to eachother

    Hi,
    let's say I have two classes, Children and Toys and now I wonder how to bind a toy to a child. A child can have many toys but a toy can only have one owner.
    class Children{
    String name;
    int age;
    class Toys{
    String name;
    String desc;
    What I can think of is that either creating an ArrayList or something in the childrens class that stores the toyobjects or maybe a reference to a toyobject with a unique identifier (database thinking) or should i have a attribute in the toys class like an owner or something that binds the toy to a child.
    This is pretty simplified but just so I can get a hang of it.

    Ok,
    so if I understand you right I will add a list to the childclass, and it will be something like this:
    class Children{
    String name;
    int age;
    ArrayList <Toys> [] toys;
    //store all childobjets
    ArrayList <Children> [] childs = new ArrayList<Children>();
    public Children(String Name, int Age){
    name=Name;
    age = Age;
    toys = new ArrayList<Toys>();
    public addChild(Children child){
    childs.add(child);
    class Toys{
    String name;
    String desc;
    public Toys(String Name, String Desc){
    name=Name;
    desc=desc;
    and then I create some more methods to set and get and a method to add a toy to the child object.

  • Photoshop bug: Smart Objects overwriting other Smart Objects when edited and saved in Illustrator

    Experiencing issues when working with a large number (over 200) vector smart objects brought into Photoshop CS4 from Illustrator. 
    Things seemed to be going along nicely; if I needed to edit a Smart Object, I could double-click it, it would open in Illustrator and then I could edit and save it.  Return to Photoshop and the Smart Object is updated.  Swell and dandy.  The issue started happen when I hit a large quantity of either vector smart objects (remember, over 200) or the many layers and groups within Photoshop (must be over 500).  When I would double-click, open, edit, and save the vector Smart Object, the Photoshop Smart Object I was working on would update AND another/several other Smart Objects would update as well.  Which, of course, would ruin the artwork, as suddenly I was seeing several instances of the same object.  If it hadn't have been for ForeverSave, I many not have recovered the work.
    It's rather hard to isolate the issue to see what's causing the problem.  Here are some of the possible causes:
    Running Snow Leopard on Mac
    Many, many Smart Objects in file, perhaps enough to ruin the naming convention and cause bugs when Photoshop referenced the temp file
    Many, many Photoshop layers and groups
    Illustrator vector files copy+pasted from several different files (affects the naming convention perhaps?)
    Some groups/layers in Photoshop are duplicates
    To help make it a little clearer, you should know:
    Running the most updated software / OS (that is until CS5 comes out)
    Smart Objects showed no error until I had actually opened, edited, and saved the referenced temp file (i.e. VectorSmartObject1.ai)
    Files saved and worked on from Dropbox (network folder)
    Not looking for much of an answer to this question; I just wanted to see if anyone else had come across this bug.  Also, Adobe PLEASE look into this as you begin testing for the next update.  I have the file(s) if you need to replicate the issue.  My best guess is that the naming convention of Vector Smart Objects has an odd character limit so when Vector Smart Object 200.ai is saved, Vector Smart Object 2.ai gets overwritten.

    Have you tested this with Photoshop CS5 and Illustrator CS5? (the current versions, that came out last month)
    If you duplicated a smart object layer, both layers refer back to the same file content. So when you change the file, both layers would be updated.  That is intentional and explained in your manual.  If you didn't realize this, that could explain what you are seeing.
    If you placed separate files, then they should not be updated at the same time, because they will refer to separate files.
    Yes, Smart Objects only update when you save the file.
    You would need over 4 billion smart objects in one document to get Photoshop confused about which one refers to which file.  And since the layer limit is much less than 4 billion, I doubt that is the cause.
    There is no naming convention involved. We don't limit the filenames (except to platform standards and to include a file type extension).

  • HTML5 Canvas: addChild and position

    Hey Guys
    I have an item on the stage called 'square1', I have added a symbol from the library and given it the name 'circle1'.
    I wish to position circle1 at the exact location of square1, my question is - how would I go about doing that?
    Thanks

    Knowing JavaScript is going to be essential for you to use Canvas. If you really don't want to get your hands into the code you should do your best with the timeline.
    If you're ready to take the canvas plunge then JavaScript has to become a tool for you. The second page of what I linked would show you that for almost every bit of ActionScript you might be used to, there's a translation over to JavaScript that's necessary. So every time you go to do something you're going to be right back here.
    The best option just might be for you to take a look at EaselJS. There's lots of very simple demos that can get you started with HTML5/Canvas and will give you answers you want in Flash. Take a look:
    CreateJS | A suite of Javascript libraries and tools designed for working with HTML5

  • Canvas - controlling object with js keypress function

    Hi,
    Using Flash CC and a HTML5 Canvas I am trying to control a ball (instance name ball_mc) on stage with the arrow keys using JS. Tried a few variations, but no luck. Any suggestions?
    ty
    this.addEventListener("keypress", keyDownHandler.bind(this), true);
    function keyDownHandler(event) {
              // get which key the user pressed
              var key = event.which;
              switch (key) {
                             case 37: // left key
                                            // move the ball 1 left by subtracting 1 from ballX
                 this.ball_mc.x -= 1;
                 break;
                             case 39: // right key
                     // move the ball 1 right by adding 1 to ballX
                     this.ball_mc.x += 1;
                      break;

    Hi,
    You can try the following code .This will help you acheive the desired movement on key down .
    document.onkeydown = keyHandler.bind(this);
    function keyHandler(event) {
                var e = event||window.event;
               switch (e.keyCode) {
                             case 37: this.ball_mc.x-= 1;
                                                 break;
                             case 39: this.ball_mc.x += 1;
                                                 break;
    Thanks,
    Sangeeta      

  • HttpConnection fron a canvas extended object

    I am trying to establish an HttpConnection from a canvas extended by invoking a static method from a class i created. The thing is that the connection doesn�t even start and the servlet i am testing it on is perfectly find. please help me, i got an urgent assignment to present and i am stuck.

    I am trying to establish an HttpConnection from a canvas extended by invoking a static method from a class i created. The thing is that the connection doesn�t even start and the servlet i am testing it on is perfectly find. please help me, i got an urgent assignment to present and i am stuck.

  • Media queries keep overwriting eachother

    I have a created two media queries. However when I edit one, the other is over written with the previous media query's properties. I have noticed that the primary html div holds the class of whatever the most recently edited media query is.  Can someone please give me some idea of what is happening?
    Here is an example of the html:
    <div class="mainGraphic">
    <img src="images/home_scholarship.jpg" alt="" class="mainGraphic" /></div>
    <div class="mainContent">
    <div class="bannerHome"><img src="images/banner_iphone6.png" alt="" class="bannerSmall750" /></div>
    <div class="bannerHome"><img src="images/banner_tv.png" alt="" class="bannerSmall750-2" /></div>
    <div class="bannerHome"></div>
    <div class="bannerHome"><img src="images/banner_internet.png" alt="" class="bannerSmall750-3" /></div>
    <div class="bannerHome"><img src="images/banner_tvonmyside.png" alt="" class="bannerSmall750-4" /></div>
      </div>
    Here is an example of the CSS:
    @media screen and (max-width:750px){
    .mainContent {
      padding-top: 5px;
    .bannerSmall750 {
      width: 182px;
      margin-left: -15px;
    .bannerSmall750-2 {
      width: 172px;
      margin-left: -10px;
    .bannerSmall750-3 {
      width: 177px;
      margin-left: -15px;
    .bannerSmall750-4 {
      width: 173px;
      margin-left: -15px;
    .mainBanner750 {
      width: 750px;
    #container {
      width: 750px;
      height: auto;
      margin-top: 1px;
      margin-right: auto;
      margin-left: auto;
      text-align: left;
      padding-left: 1px;
      background-color: rgba(255,255,255,1.00);
      -webkit-box-shadow: 0px 0px 18px hsla(0,0%,14%,1.00);
      box-shadow: 0px 0px 18px hsla(0,0%,14%,1.00);
    .mainGraphic {
      width: 750px;
      height:
    @media only screen and (max-width:480px){
    .mainContent {
      padding-top: 5px;
    .mainBanner480 {
      width: 380px;
      height:170px;
    #container {
      width: 480px;
      height: 780px;
      margin-top: 1px;
      margin-right: auto;
      margin-left: auto;
      text-align: left;
      padding-left: 1px;
      background-color: rgba(255,255,255,1.00);
      -webkit-box-shadow: 0px 0px 18px hsla(0,0%,14%,1.00);
      box-shadow: 0px 0px 18px hsla(0,0%,14%,1.00);
    .headerLogo {
      margin-bottom: 10px;
      margin-top: -16px;
      padding-left: 113px;
      padding-top: px;
      padding-bottom: 15px;
    .headerLinks a {
      text-decoration: none;
      color: rgba(208,208,208,1.00);
      padding-left: 0px;
      font-size: 14px;
      font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
      padding-right: 34px;
      right: -69px;
      bottom: -92px;
      position: relative;
      margin-right: 7px;
      margin-left: -42px;
    .mainGraphic {
      width: 480px;
      height:
    .mainContent .bannerHome img1 {
    .mainContent .bannerHome img2 {
      width: 200px;
      margin-left: 50px;
    .mainContent .bannerHome img3 {
        width: 200px;
      margin-left: 20px;
    .mainContent .bannerHome img4 {
    width: 200px;
      height:286px;
      margin-left: 40px;
    .smallBanner480-1 {
      width: 200px;
      height:296px;
      margin-left: 30px;

    Wow, had I known I wouldn’t have updated either. I always thought updates were good.
    Okay, so I already have my overall html codes and divs completed.
    So I go to the CSS Designer panel, select my primary css file under ‘Sources’. 
    I select the ‘@Media panel and select the ‘plus’ sign to add new media queries. I define my media queries of screen and (max-width:768px) and screen and(max-width:480px).
    Once that’s done and they show up under the  ‘@Media’ panel, I go back to select my primary css file under the ‘Sources’ panel. Select ‘global’ under the ‘@Media’ panel and choose the selector I want to target.
    I select .mainGraphic and right click to select ‘Duplicate into media query’ then choose my first target of ‘screen and  (max-width:768px)
    Once I see that selector in my ‘screen and (max-width:768px) query I begin to apply different properties to it to make it adjust as desired.
    I follow the same procedure with duplicating into the ‘screen and (max-width:480px)’ query and adjusting to properties as desired.
    This is when I notice from switching back to my first designed query that the changes made in the 480px are now on the 768px query and vice versa.

  • Canvas not displaying controls added with addChild

    I have a custom class holding some information, a property in
    the class is an XML string and another method parses the XML add
    creates controls (labels and buttons) based on the xml. I also have
    a variable named renderer which is a mx.containers.Canvas. After
    the XML is loaded and the controls are added using
    Canvas.addChild() I add the Canvas to my stage. The problem I'm
    running into is that even though the Canvas is added to the stage,
    I cannot see any of the controls inside of the canvas. Doing a
    trace(Canvas.numChildren()); I can see that I have added 101
    children to my canvas container (which is what my xml file shows)
    however they will not display. I know the canvas has been added to
    the stage because I can see the scroll bars when i set the policies
    to "on" and it even sets the scroll bars correctly if the
    components are too big for the canvas and would have to be scrolled
    down to see them all, it just doesn't show any of the components.
    Anyone run into a similar issue?

    Did you set an explicit width and height (or percentWidth and
    percentHeight, or styles top, left, top, bottom) on the controls
    you create? By default controls have 0x0 size. Creating controls in
    MXML causes additional code to be generated which gives the
    controls default sizes, but it won't happen in your own
    ActionScript code.

  • Adding a goemetry object in an already started applet, behvior ?

    Hello there,
    I would like to add a geometric form (cube, box, cone etc..) in an already
    started applet. I think creating a specific behavior would be the most
    appropriate.
    Has anybody done this kind of thing before ?
    Many thanks.
    Gwena�l

    Great thread! I am having difficulty with removing objects from a scene graph. See source code below:
    addTarget creates a grpahicsObject (class consisting of some data, mainly a 3d object which is attached to a transformGroup).
    //function to add an aircrafat to display
         //attemps to create the aircraft in the specified location
         //returns false if the spot is not null
         public boolean addTarget(int location, float x, float y, float z)
              if(targets[location]!=null)
                   return false;
              //create transform vector
              Vector3f targetTransform = new Vector3f(x,y,z);
              //create the object
              targets[location]= new GraphicsObject(targetTransform, TARGET_COLOR);
              //add it to the scene graph
              sadist.addObject(targets[location].getTransformGroup());
              return true;
    //sadist is an object that contains my universe and pretty much controls my display
    //the add object code adds the created to the scene graph by adding the transform group to a newly created branchgroup and than adding that to the mother branchgroup. The mother branchgroup was attached to the simple universe object (see code snipit)
    private Applet CreateWorld()
              setLayout(new BorderLayout());
         //create a new canvas
         Canvas3D canvas3D = new Canvas3D(null); // NEED TO PASS IN SOMETHING
         //add canvas to applet
         add("Center", canvas3D);
         BranchGroup scene = createSceneGraph();
         mother = new BranchGroup();
              mother.setCapability(BranchGroup.ALLOW_DETACH);
              mother.setCapability(Group.ALLOW_CHILDREN_READ);
         mother.setCapability(Group.ALLOW_CHILDREN_WRITE);
         mother.setCapability(Group.ALLOW_CHILDREN_EXTEND);
         mother.addChild(scene);
         // SimpleUniverse is a Convenience Utility class
         // code reuse saves time
         simpleU = new SimpleUniverse(canvas3D);
              ViewingPlatform vp = simpleU.getViewingPlatform();
              TransformGroup steerTG = vp.getViewPlatformTransform();
              //create my transform
              Transform3D t3d = new Transform3D();
              steerTG.getTransform(t3d);
              //lookAt( from here, look here, vector up)
              t3d.lookAt( new Point3d (2,2,2),
                             new Point3d (0,0,0),
                             new Vector3d(0,1,0) );
              t3d.invert(); //inverted since the position is relative to the viewer
              //set the transform for the transform group
              steerTG.setTransform(t3d);
              simpleU.addBranchGraph(mother);
         return(this);
         //function to add transofrm group to scene graph
         public void addObject(TransformGroup object)
              //should I create a new branch graph, add the transform group, and then
              //add that to the simple u
              //I don't think this is right as I have no real way of identifying this
              //I need to look into a removeChild or something
              //could result in 1000's of null nodes on scene graph
              //yuck...
              System.out.println("going to add the transformg group to the branchgroup");
              BranchGroup t = new BranchGroup();
              t.setCapability(BranchGroup.ALLOW_DETACH);
              t.setCapability(Group.ALLOW_CHILDREN_READ);
              t.setCapability(Group.ALLOW_CHILDREN_WRITE);
         t.setCapability(Group.ALLOW_CHILDREN_EXTEND);
              t.addChild(object);
              t.compile();
              //simpleU.addBranchGraph(t);
              mother.addChild(t);
    When I run the code with a tester function I can add the objects just fine but when I try to remove them (see code below) it doesn�t work.
    //removal of targets will take place
         public void removeObject(int location) throws CapabilityNotSetException
              try
                   //I tried detaching the branchgroup via the detach() function
                   //howeve that wasn't successful either.
                   mother.removeChild(location);
              catch(CapabilityNotSetException e)
                   throw e;
    Any advice you could give would be great.
    Thanks,
    Mike

  • Class display objects visible=false

    Hi there,
    I have an app that displays XML as items. I am taking the createLayout() and trying to create a class that i can call from my custom component rather than having tons of code in the same file. The issue i am having is that when i call it, and run/debug, the display objects (text,links,date..) all have their visible property set to false. This happens even though I set the property to true in my code. Please help!
    package com.ryancanulla.utils
         import flash.display.Sprite;
         import flash.events.MouseEvent;
         import flash.net.URLRequest;
         import flash.net.navigateToURL;
         import flash.text.TextFormat;
         import mx.collections.XMLListCollection;
         import mx.containers.Canvas;
         import mx.containers.HBox;
         import mx.containers.VBox;
         import mx.controls.CheckBox;
         import mx.controls.ComboBox;
         import mx.controls.LinkButton;
         import mx.controls.Text;
         public class CreateLayout extends Sprite {
         //     Display Vars
              private var vBox:VBox;
              private var hBox:HBox;
              private var titleText:LinkButton;
              private var itemInfo:Text;
              private var abstract:Text;
              private var archive:CheckBox;
              private var rateItem:ComboBox;
              private var category:ComboBox;
              private var container:VBox;
              private var clickURL:Text;
              private var canvas:Canvas;
              private var titleFormat:TextFormat;
              public function CreateLayout(listCollection:XMLListCollection)
                   listCollection = listCollection;
                   container = new VBox();
                   var categoryLabels:Array = new Array("Health","Industrial","Emerging Tech","Food & Ag");
                   var rateLabels:Array = new Array("Positive","Neutral","Negative");
                   for(var i:int=0; i<listCollection.length; i++) {
                        canvas = new Canvas();
                        hBox = new HBox();
                        titleText = new LinkButton();
                        titleFormat = new TextFormat();
                        itemInfo = new Text();
                        abstract = new Text();
                        archive = new CheckBox();
                        rateItem = new ComboBox();
                        category = new ComboBox();
                        clickURL = new Text();
                        titleText.label = listCollection.getItemAt(i).title;
                        titleText.addEventListener(MouseEvent.CLICK, getURL);
                        titleText.width = 400;
                        clickURL.text = listCollection.getItemAt(i).clickurl;
                        clickURL.visible = false;
                        clickURL.includeInLayout = false;
                        itemInfo.text = listCollection.getItemAt(i).source + " | " + listCollection.getItemAt(i).date;
                        itemInfo.y = 25;
                        abstract.text = listCollection.getItemAt(i).abstract;
                        abstract.y = 42;
                        abstract.visible = true;
                        abstract.includeInLayout = true;
                        abstract.width = 400;
                        abstract.height= 60;;
                        archive.label = "Archive";
                        category.prompt = "Category";
                        category.dataProvider = categoryLabels;
                        category.rowCount = categoryLabels.length;
                        category.visible = false;
                        category.includeInLayout = false;
                        category.width = 95;
                        category.height = 20;
                        rateItem.prompt = "Rate";
                        rateItem.dataProvider = rateLabels;
                        rateItem.visible = false;
                        rateItem.includeInLayout = false;
                        rateItem.width = 95;
                        rateItem.height = 20;
                        canvas.addChild(titleText);
                        canvas.addChild(clickURL);
                        canvas.addChild(itemInfo);
                        canvas.addChild(abstract);
                        canvas.addChild(hBox);
                        hBox.addChild(archive);    
                        hBox.addChild(category);
                        hBox.addChild(rateItem);
                        hBox.y = abstract.y + 60;
                        hBox.percentWidth = 80;
                        hBox.percentHeight = 80;
                        //archive.addEventListener(Event.CHANGE, toggleArchive);    
                        container.addChild(canvas);         
                   container.x = 10;
                   container.y = 10;
                   container.visible = true;
                   addChild(container);
            // Called when someone clicks on the titleLink. This function pulls the
            // origional website URL up in a seperate browser window
            private function getURL(e:MouseEvent):void {
                      var link:LinkButton = e.currentTarget as LinkButton;
                      var canvas:Canvas = link.parent as Canvas;
                      var clickURL:Text = canvas.getChildAt(1) as Text;
                      var url:URLRequest = new URLRequest(clickURL.text);
                      navigateToURL(url);
                   trace(clickURL.text);
    Where I instantiate the class. List collection is an XMLListCollection which contains XML data.
    private var createLayout:CreateLayout;
    createLayout = new CreateLayout(listCollection);

    container is from the Vbox class so I don't see that here and there might be something in there that is causing some problem.
    But I don't think that is the only problem. I think this seems like the same problem that you have going in your other post.
    I don't see anyplace that you addChild your CreateLayout instance. container has been added to your CreateLayout instance, but where is the CreateLayout instance added to some other display list.
    Also it looks like almost everything you add to canvas is set to be invisible. So without knowing what is in a Canvas instance it is hard to know what would show up anyways.

  • Multiple Instances Object Calling Getting #1009 Error

    Hi,
    I believe this has to be a logical explanation for this. I have the code here as follows:
    private function action():void{
        thematicMap.passBox(canvas,regions);
        thematicMap.drawthematicMap.passBox(canvas);  
        //Setting the Canvas
        thematicMap.setCanvas(0,0,30,50);     
        thematicMap.drawthematicMap.draw(regions);
        thematicMap.setCanvas(24,24,453,455);
        thematicMap.drawthematicMap.draw(regions);     
    This does show two instances of the thematicMaps, which is what works in main.zip. However, what I really want to do is this:
    private function action():void{
        thematicMap.passBox(canvas,regions);
        thematicMap.drawthematicMap.passBox(canvas); 
                   a = new ThematicMap();
       b = new ThematicMap();  
        //Setting the Canvas
        a.setCanvas(0,0,30,50);
                    b.setCanvas(24,24,453,455);     
                   //Draw
                  a.drawthematicMap.draw(regions);
      b.drawthematicMap.draw(regions);     
    The output of the application below is only a blank screen. I then investigated and added some try and catch clauses to see what errors there are,
    try {
             //Setting the Canvas
         a.setCanvas(0,0,30,50);     
         b.setCanvas(24,24,453,455); 
                  catch (errObject:Error) {Alert.show("An error occurred: " + errObject.message);}
    The results I got was Error #1009. How come that I have provided the parameters and the return is null object of reference?
    Thanks for your help.
    Alice

    To answer your second point regarding if I had added a child to my  canvas to draw, here is the snippet:
    public function draw(arr:Array):void{
                 regions = arr;    
                 component_width = [];
                 component_height= [];       
                 for (var s:String in regions) {
                    trace("\n" + s);
                    shape = new UIComponent();  
                    gr = shape.graphics;
                    gr.lineStyle(3);//Define line style  
                    coords = regions[s];
                    gr.moveTo(coords[0],coords[1]);               
                 for (var i:int = 2; i < coords.length; i += 2) gr.lineTo(coords[i],coords[i + 1]);  
                     trace(coords);                
                     gr.lineTo(coords[0],coords[1]);    //return the code back to the beginning   
                     gr.endFill(); //Put this in if there is a color
                     canvas.addChild(shape);             
    This is what is in my setCanvas function:
    public function setCanvas(x:Number,y:Number,width:Number,height:Number):void{       
                canvas.setActualSize(width,height);
                canvas.x = x;
                canvas.y = y;  
                coordinate_conversion(regions);
                new_coordinate_conversion(regions);
    What else could be wrong here?
    Thanks for your help.
    Alice

  • Canvas and transparency

    I'm string to use AWT's Canvas class to stack 2 Canvasses on top of eachother (this is going to be extended to a full custom gui so I can't just merge it into one).
    Right now I have one solid canvas as base image (containing a png) and one canvas stacked on top of the base one with 'alpha' as transparency value. Whatever I try, I can't get the top canvas to blend into the lower one - it keeps blending with an opaque white.
    I saw people doing things similar to me and I thought I grasped how its supposed to work (keep an alpha channel around and the render engine will allow the content of a frame to be blended when outputted.
    This is currently my paint method in the canvas class:
    public void paint(Graphics g) {
              // When we don't have a valid image, don't bother
              if (img == null || img.getWidth(this) == -1) { super.paint(g); return; }
              // Upgrade to Graphics2D
              Graphics2D g2d = (Graphics2D) g;
              // Check if we need to rerender our internal composite buffer (if the alpha changed of no buffer exists)
              if (previous_alpha != alpha || bi == null) {
                   // Reinit the whole buffer - I'm still searching for a way to simply empty the buffer instead of rebuilding it
                   //bi = new BufferedImage(img.getWidth(this),img.getHeight(this),BufferedImage.TYPE_INT_ARGB);
                   bi = new BufferedImage(img.getWidth(this),img.getHeight(this),BufferedImage.TYPE_4BYTE_ABGR);
                   // Derrive a graphics object from the buffer to draw in
                   Graphics2D big = bi.createGraphics();
                   // Insert composite manager here
                   big.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha));
                   // Draw the whole image into the buffer using the composite defined above
                   big.drawImage(img, 0, 0, this);
              // Draw the composite buffer onto the panel
              g2d.drawImage(bi, 0, 0, this);
         }

    It is easy to draw both images in a single component: the opaque image first and the
    translucent on top. But if you definately want to use separate components you can.
    I can't get the top canvas to blend into the lower one - it keeps blending with an
    opaque white.
    Canvas is an AWT, heavyweight component. You won't be able to see through it.
    One way to do this is to draw your opaque image on a JPanel and ovelay it with a
    JComponent (which is non-opaque by default) on which you draw your translucent image. If
    you have trouble aligning them you could mount both in a JPanel with an OverlayLayout.
    JPanel panel = new JPanel();
    OverlayLayout overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);
    panel.add(translucentTopComponent);  // May have to change the order
    panel.add(opaqueBottomComponent);    // but I think this is correct.
    I'm still searching for a way to simply empty the buffer instead of rebuilding it
    // To clear the image background for drawing graphics:
    Graphics2D big = (Graphics2D)bi.getGraphics();
    big.setBackground(getBackground());
    big.clearRect(0,0,bi.getWidth(),bi.getHeight());
    // draw graphics on bi
    big.dispose();
    // Or, if the image will fill bi:
    Graphics2D big = (Graphics2D)bi.getGraphics();
    // Insert composite manager here
    big.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha));
    // Draw the whole image into the buffer using the composite defined above
    big.drawImage(img, 0, 0, this);
    big.dispose();

Maybe you are looking for