Variable size array in a FlowPane

If i have an array of variable size (for example a array of cards).
How can i build something to show the elements(in a FlowPane for example) and each of them having its own controller (fxml + controller for each card), so the container (flow pane) of the elements (cards) can have it's elements swaped, removed or added new ones?
Controller:
public class HandController extends FlowPane implements Initializable{
    @Override public void initialize(URL arg0, ResourceBundle arg1){
    public void setHand(ArrayList<Cards> Hand){
        //this would work if the hand were static
        for(int i = 0; i < Hand.size(); ++i){
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("CardView.fxml"));
            CardController controller = new CardController();
            fxmlLoader.setController(controller);
            fxmlLoader.setRoot(controller);
            Parent card = (Parent)fxmlLoader.load();
            fxmlLoader.setRoot(card);
            this.getChildren().add(card);
            controller.setCard(Hand.get(i));
}Fxml:
<fx:root type="FlowPane" xmlns:fx="http://javafx.com/fxml"
         stylesheets="view/Style.css">
    <children>
        <!--should i put something here?-->
    </children>
</fx:root>

Well, I was bored...
This "game" has a hand of up to five cards. You can deal from a deck to the hand, and then play (or discard) a card by double-clicking on it.
The model comprises a Card class, a Deck class, and a GameModel class. The last one tracks the hand and deck and the relationship between them. Card and Deck were written from my memory of reading an example of using Enums by Josh Bloch.
Card.java
package cardgame;
public class Card {
     public enum Rank {
          Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King
     public enum Suit {
          Clubs, Diamonds, Hearts, Spades
     private final Rank rank;
     private final Suit suit;
     public Card(Rank rank, Suit suit) {
          this.rank = rank;
          this.suit = suit;
     public Rank getRank() {
          return rank;
     public Suit getSuit() {
          return suit;
     @Override
     public String toString() {
          return String.format("%s of %s", rank, suit);
     @Override
     public int hashCode() {
          final int prime = 31;
          int result = 1;
          result = prime * result + ((rank == null) ? 0 : rank.hashCode());
          result = prime * result + ((suit == null) ? 0 : suit.hashCode());
          return result;
     @Override
     public boolean equals(Object obj) {
          if (this == obj)
               return true;
          if (obj == null)
               return false;
          if (getClass() != obj.getClass())
               return false;
          Card other = (Card) obj;
          if (rank != other.rank)
               return false;
          if (suit != other.suit)
               return false;
          return true;
}Deck.java
package cardgame;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import cardgame.Card.Rank;
import cardgame.Card.Suit;
public class Deck {
     private final List<Card> cards;
     private Deck() {
          cards = new LinkedList<Card>();
          for (Suit suit : Suit.values())
               for (Rank rank : Rank.values())
                    cards.add(new Card(rank, suit));
     public static Deck newDeck() {
          return new Deck();
     public static Deck shuffledDeck() {
          return newDeck().shuffle();
     public Deck shuffle() {
          final List<Card> copy = new ArrayList<Card>(cards.size());
          Random rng = new Random();
          while (cards.size() > 0) {
               int index = rng.nextInt(cards.size());
               copy.add(cards.remove(index));
          cards.clear();
          cards.addAll(copy);
          return this;
     public Card deal() {
          return cards.remove(0);
     public int size() {
          return cards.size();
}GameModel.java
package cardgame;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class GameModel {
     private ObservableList<Card> hand;
     private Deck deck;
     private BooleanProperty canDeal;
     public GameModel() {
          this.hand = FXCollections.observableArrayList();
          this.deck = Deck.newDeck().shuffle();
          this.canDeal = new SimpleBooleanProperty(this, "canDeal");
          canDeal.bind(new BooleanBinding() {
                    super.bind(hand);
               @Override
               protected boolean computeValue() {
                    return deck.size() > 0 && hand.size() < 5;
     public ObservableList<Card> getHand() {
          return hand;
     public ReadOnlyBooleanProperty canDealProperty() {
          return canDeal;
     public boolean canDeal() {
          return canDeal.get();
     public void deal() throws IllegalStateException {
          if (deck.size() <= 0) {
               throw new IllegalStateException("No cards left to deal");
          if (hand.size() >= 5) {
               throw new IllegalStateException("Hand is full");
          hand.add(deck.deal());
     public void playCard(Card card) throws IllegalStateException {
          if (hand.contains(card)) {
               hand.remove(card);
          } else {
               throw new IllegalStateException("Hand does not contain " + card);
}The CardController is the controller for a CardView. It takes a reference to a Card and its initialize method initializes the view to display it (the view is just a simple label).
CardController.java
package cardgame;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
public class CardController {
     private final Card card;
     @FXML
     private Label label;
     public CardController(Card card) {
          this.card = card;
     public void initialize() {
          label.setText(String.format("%s%nof%n%s", card.getRank(),
                    card.getSuit()));
}The HandController is the controller for the display of the hand. This is where most of the action happens. The trick here is that it requires a reference to a GameModel, which needs to be injected from somewhere, so we need a setModel(...) method, or something similar. I didn't want to assume the order of events: i.e. whether the model is injected before or after the initialize() method is invoked. To keep this flexibility, I used an ObjectProperty to wrap the model, and listen for changes to it. When the model is updated, I register a listener with the hand (exposed by the model). This listener in turn rebuilds the views of the cards when the hand changes. There's also a "deal" button, whose disabled state is managed by binding to a property in the model (using a neat trick from the Bindings class to allow the model value to be dynamic).
HandController.java
package cardgame;
import java.io.IOException;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ListChangeListener;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
public class HandController {
     private ObjectProperty<GameModel> model;
     @FXML
     private Pane container;
     @FXML
     private Button dealButton;
     public HandController() {
          this.model = new SimpleObjectProperty<GameModel>(this, "model", null);
          final ListChangeListener<Card> handListener = new ListChangeListener<Card>() {
               @Override
               public void onChanged(Change<? extends Card> change) {
                    container.getChildren().clear();
                    try {
                         for (Card card : model.get().getHand()) {
                              container.getChildren().add(loadCardView(card));
                    } catch (IOException e) {
                         e.printStackTrace();
          model.addListener(new ChangeListener<GameModel>() {
               @Override
               public void changed(
                         ObservableValue<? extends GameModel> observable,
                         GameModel oldValue, GameModel newValue) {
                    if (oldValue != null) {
                         oldValue.getHand().removeListener(handListener);
                    if (newValue != null) {
                         newValue.getHand().addListener(handListener);
     public void setModel(GameModel model) {
          this.model.set(model);
     public void initialize() {
          dealButton.disableProperty().bind(
                    Bindings.selectBoolean(model, "canDeal").not());
     private Node loadCardView(final Card card) throws IOException {
          FXMLLoader loader = new FXMLLoader(getClass().getResource(
                    "CardView.fxml"));
          CardController controller = new CardController(card);
          loader.setController(controller);
          Node cardView = (Node) loader.load();
          cardView.setOnMouseClicked(new EventHandler<MouseEvent>() {
               @Override
               public void handle(MouseEvent event) {
                    if (event.getClickCount() == 2) {
                         model.get().playCard(card);
          return cardView;
     public void dealCard() {
          model.get().deal();
}Here are the FXML files:
CardView.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.control.Label?>
<?import java.lang.String?>
<StackPane xmlns:fx="http://javafx.com/fxml" prefHeight="150" prefWidth="80" minWidth="80" maxWidth="80" minHeight="150" maxHeight="150">
     <Label fx:id="label" >
     </Label>
     <styleClass>
          <String fx:value="card"/>
     </styleClass>
</StackPane>Hand.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ScrollPane?>
<?import java.lang.String?>
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="cardgame.HandController" >
     <center>
          <FlowPane hgap="5" vgap="10" fx:id="container">
          </FlowPane>
     </center>
     <bottom>
          <Button text="Deal" onAction="#dealCard" fx:id="dealButton"/>
     </bottom>
</BorderPane>The overall application is managed by a Game.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="cardgame.GameController">
     <center>
          <fx:include source="Hand.fxml" fx:id="hand" />
     </center>
</BorderPane>with a GameController:
package cardgame;
import javafx.fxml.FXML;
public class GameController {
     @FXML private HandController handController ;
     private GameModel model ;
     public GameController() {
          model = new GameModel();
     public void initialize() {
          handController.setModel(model);
}Game.java is the main class:
package cardgame;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class Game extends Application {
     @Override
     public void start(Stage primaryStage) throws IOException {
          Scene scene = new Scene(FXMLLoader.<Parent>load(getClass().getResource("Game.fxml")), 600, 400, Color.DARKGREEN);
          scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
          primaryStage.setScene(scene);
          primaryStage.show();
     public static void main(String[] args) {
          launch(args);
}and then a style sheet
style.css:
@CHARSET "US-ASCII";
.card {
     -fx-background-color: white ;
     -fx-border-color: black ;
     -fx-border-radius: 5 ;
     -fx-border-style: solid ;
     -fx-padding: 5 ;
.card .label {
     -fx-text-alignment: center ;
}

Similar Messages

  • How can I create a variable size array?

    How can I create a variable size array?

    ok then how can i create a new vector object?If you don't know that, you need to go back to your text book and study some more. Or read the tutorial on the basics of Java: http://java.sun.com/docs/books/tutorial/java/index.html
    After reading that you can move on to: http://java.sun.com/docs/books/tutorial/collections/index.html
    Anyway, the answer to your question is, of course:
    Vector v = new Vector();(But you should probably use ArrayList instead of Vector.)

  • Variable size array output from dynamic dispatch class method on FPGA

    I have a Parent class on the FPGA that will serve as a template/framework for future code that will be developed. I had planned on creating a child class and overriding a couple methods. The child class constant would be dropped on the block diagram so the compiler wouldn't have any trouble figuring out which method (parent's or child's) should be used (i.e. the parent's method will never actually be used and won't be compiled with the main code). The output of one of the methods is an array. This array will have a different size depending on the application. I defined the array size as variable. In the child method, there is no question about the size of the array so the compiler should be able to figure it out. However, when I try to compile, I get an error about the array size. I can't figure out any way around it. Any thought would be greatly appreciated! 
    Thanks, Patrick
    Solved!
    Go to Solution.
    Attachments:
    FPGA Test.zip ‏1194 KB

    Wait what?
    Can we use dynamic dispatch VIs on FPGA?  Really?  I was completely unaware of this.  Obviously the dependencies need to be constant and known at compile time but...... This would have saved me a lot of headaches in the last few months.
    Since which LV version is this supported?
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • Variable size array of checkboxes

    I am new to weblogic. I am using weblogic 8.1 SP3.
    My problem is that i have to display a table with first coloumn of each row a name and rest coloumns should contain checkboxes. Each row has same number of checkboxes. But the number of checkboxes in each row everytime page is loaded is variable.
    If anyone can tell me how to do this and how to bind data to form bean. I tried using a repeater tag with a Boolean array but of no use.
    Thanks in advance
    Akshay

    Please create a new default application and drop the checkbox folder into
    the web project and run the jpf.
    Thanks
    Vimala
    <Vimala Ranganathan> wrote in message news:[email protected]..
    Hi Akshay
    I have attached a sample that will show a page that will take in the
    number of checkboxes the page will have (like you can get this as request
    attribute, req parameter etc) and displays the page using repeater tag.
    Steps:
    Unzip the file and open with workshop IDE
    Build and run the jpf in the folder checkbox
    I am not sure how to attach the file. Can you please let me know your
    email so I can send it to you?
    Thanks
    Vimala

  • Need suggestion for variable size array of primitive type.

    Hi all,
    I am working on a problem in which I need to keep an array of primitive (type int) sorted. Also I insert new elements while keeping it sorted, and at times I merge two similar arrays with unique elements.
    I would welcome suggestions on the implementation aspects as to which type/class to use. My primary consideration is performance. Here are my observations:
    1. type int
    Efficient operation, but arrays are fixed size so it makes clumsy code and overhead when the array is expanded or merged with another.
    Methods in class Arrays can be used, incl. binary search and sort.
    2. Vector, ArrayList, List, LinkedList
    Accept objects only. I can use Integer instead of int, but it will involve overhead, and I'll need to write my own sort and search routines (already done).
    For now, I choose option 2 using Vectors. Is there a better choice, or are there other options, given the conditions and consideration enumerated at the beginning?
    Appreciate any input or comments.

    mathmate wrote:
    I have not had the occasion to use them in parallel to recognize the difference. It pays to talk to people!A small benchmark is easily constructed:
    import bak.pcj.list.IntArrayList;
    import java.util.Random;
    import java.util.ArrayList;
    public class CollectionTest {
        static void testObjectsList(ArrayList<Integer> list, int n, long seed) {
            long start = System.currentTimeMillis();
            Random rand = new Random(seed);
            for(int i = 0; i < n; i++)
                list.add(new Integer(rand.nextInt()));
            for(int i = 0; i < n/2; i++)
                list.remove(rand.nextInt(list.size()));
            long end = System.currentTimeMillis();
            System.out.println("objectsList -> "+(end-start)+" ms.");
        static void testPrimitiveList(IntArrayList list, int n, long seed) {
            long start = System.currentTimeMillis();
            Random rand = new Random(seed);
            for(int i = 0; i < n; i++)
                list.add(rand.nextInt());
            for(int i = 0; i < n/2; i++)
                list.remove(rand.nextInt(list.size()));
            long end = System.currentTimeMillis();
            System.out.println("primitiveList -> "+(end-start)+" ms.");
        public static void main(String[] args) {
            long seed = System.currentTimeMillis();
            int numTests = 100000;
            testObjectsList(new ArrayList<Integer>(), numTests, seed);
            testPrimitiveList(new IntArrayList(), numTests, seed);
    }In the test above, Java's ArrayList is about 5 times faster. But when commenting out the remove(...) methods, the primitive 3rd party IntArrayList is about 4 to 5 times faster.
    Give it a spin.
    Again: just try to do it with the standard classes: if performance lacks, look at something else.

  • Return variable sizes array in methods defined by Interface

    Hi there,
    I'm not really active on this forum and I have a strange question. I have to return an array of values in an interface. But this array can be 2D or 3D... Is there a quick and dirty solution to do so?
    My first test was to typecast... of course, I cannot. We are not using C++ for a reason ;-)
    Then I guess, I should define a class defining this array or defining an 2D array of objects (1D array or value)...
    Is there any other way to do that? As you guess, a quick and dirty solution would be sufficient!! :p
    Thanks for you help, and at least for reading this post.
    PY

    Well done... I didn't go far enough in the hierarchy. I can get back the functionality of arrays even by typecasting as Object.
    Thanks!!

  • Loading COBOL file - blocked variable records and varying size arrays

    We would like to use ODI 11g to regularly to parse and load into Oracle DB 11g complex files that originate on the MVS mainframe.
    Key file characteristics are:
    1. EBCDIC encoding
    2. file contains blocked records - each block starts with a 4-byte Block Descriptor Word (BDW). BDW bytes 1-2 specify the block length stored as a 16-bit unsigned integer, i.e. PIC (5) COMP in COBOL.
    3. each file block contains multiple variable size records - BDW is followed by 1 or more variable length records. Each record starts with a 4-bytes Record Descriptor Word (RDW). RDW bytes 1-2 specify the record length stored as 16 bit unsigned integer, i.e. PIC (5) COMP in COBOL.
    4. each file record contains number of scalar fields and several varying-size arrays - COBOL OCCURS DEPENDING ON. For example:
    03 SAMPLE-ARRAY-CNT PIC S9(1) COMP-3.
    03 SAMPLE-ARRAY OCCURS 0 TO 5 TIMES DEPENDING ON SAMPLE-ARRAY-CNT.
    05 ARRAY-CD1 PIC X(5).
    05 ARRAY-CD2 PIC X(7).
    05 ARRAY-AMOUNT PIC S9(3)V9999 COMP-3.
    5, file contains fields stored as COBOL COMPUTATIONAL and COMPUTATIONAL-3.
    6. average record lengh is 1,000 bytes and each file is about 4GB
    SQL*Loader/external table functionality can handle most of these requirements on one-off basis, but collectively they present a significant challenge. The file layout can't be reversed engineered as COBOL copybook into ODI.
    Does ODI have complex file parsing capabilities that could be used to (pre-)process the file, in as few passes as possible?
    Thanks
    Petr

    Hi,
    there's a couple of options here, and I've included what I think is the simplest below (using TestStand 2.0.1).
    It's not exactly elegant though. What I've done is to put in a step that finds out the number of steps to load (based on an earlier decision - in this case a message popup step). I read a number from the limits file, and use this in the looping options of the property loader step that's loading the values into the array. I've done it with a fixed size array target here, big enough to take any incoming data. (Otherwise, knowing how many items you're going to load from the limits file, you could start with an empty array and re-size it prior to loading).
    I've cheated slightly by using the pre-expression on the property loader step to specify where th
    e data is coming from and where it's going to in the sequence on each iteration of the loop based on the Runstate.Loopindex.
    Another option is to go straight into the property loader step, and keep loading properties until the Step.Result.NumPropertiesRead = 0 (remember we're only doing this one at a time)
    Another idea would be to load in a value, and check it isn't a "flag" value (i.e. you'd never use say 999 in your array, so set the last element in your limits file to this, and drop out of the loop when this happens.
    Further still, you've got the source code for the property loader step, so you could re-write it to make a custom step that loads an array until it fails all on its own (no looping in TestStand).
    Hope this gets you going
    S.
    // it takes almost no time to rate an answer
    Attachments:
    DynamicPropertyLoader.seq ‏32 KB

  • Can the Property Loader load arrays of variable size?

    I need to run a series of tests on the same UUT, changing only one parameter at a time (for example, a frequency response test). The hardware developers would like to be able to change the values of parameters of the test at will, without making changes to the sequence. That's easy - just change the value of the parameter in the Properties file. The hard part is changing the number of iterations of the test, by ONLY adding or deleting the number of parameters from the text file. In other words, all I know during sequence editing is the types of parameters, not the values or how many. I want the test to loop as many times as there are sets of parameters in the text file.
    I would like to do this by loading the paramet
    ers as an array. But the Property Loader wants me to specify each variable while I am editing the sequence, including each individual member of the array (e.g. "Locals.Array[0].Value"). I want to do somthing like "Locals.Array[*].Value", where "*" means "all elements".
    Am I forced to write external code to load each parameter, or does TS have a native way to do this? Even better, has anybody done this already, and will you explain how? Thanks

    Hi,
    there's a couple of options here, and I've included what I think is the simplest below (using TestStand 2.0.1).
    It's not exactly elegant though. What I've done is to put in a step that finds out the number of steps to load (based on an earlier decision - in this case a message popup step). I read a number from the limits file, and use this in the looping options of the property loader step that's loading the values into the array. I've done it with a fixed size array target here, big enough to take any incoming data. (Otherwise, knowing how many items you're going to load from the limits file, you could start with an empty array and re-size it prior to loading).
    I've cheated slightly by using the pre-expression on the property loader step to specify where th
    e data is coming from and where it's going to in the sequence on each iteration of the loop based on the Runstate.Loopindex.
    Another option is to go straight into the property loader step, and keep loading properties until the Step.Result.NumPropertiesRead = 0 (remember we're only doing this one at a time)
    Another idea would be to load in a value, and check it isn't a "flag" value (i.e. you'd never use say 999 in your array, so set the last element in your limits file to this, and drop out of the loop when this happens.
    Further still, you've got the source code for the property loader step, so you could re-write it to make a custom step that loads an array until it fails all on its own (no looping in TestStand).
    Hope this gets you going
    S.
    // it takes almost no time to rate an answer
    Attachments:
    DynamicPropertyLoader.seq ‏32 KB

  • Getting a C variable length array

    Hello,
    I'm working on a DLL library. One of the functions should return to LabView a lot of data.
    By the moment I'm doing something like this (using 'by reference' parameters):
    int getDataFromC(int* data1, char* data2, double* data3); 
    The function returns an error code, which is used to know everything goes fine. The memory of each parameter is allocated by LabView when it calls the library function. In C, the function doesn't allocate memory, it just copy the information to the space allocated by LabView (*data1 = xxx. Then LabView uses it by reading each parameter. It works fine.
    The problem is that part of the data that comes from the DLL are arrays. These arrays are generally variable length arrays. Each array always comes with other value, which describes the length of the array. So the returned array can change its length.
    By the moment I'm assuming LabView allocates enough memory to let the C code writes all the array data. But it's not a good practice...
    For example:
    int getArrayFromC(int* len, int array[]);
    The C code writes the length value to the '*len' variable to inform LabView the size of the array, and writes the N ints to the array (assuming there is enough space allocated by LabView). 
    What's the array's length that LabView uses in this case?
    On the other hand, I'd prefer to use something like:
    int getArrayFromC(int* len, int* array[]);
    In this case I can control the length of the array. It is a array-by-reference situation. I could change the array used by LabView.
    What do you recommend? I just need to get a variable length array.
    Thanks!
    Mauricio

    LabVIEW allocates as much memory for an array as is needed.  They are always variable length, as LabVIEW dynamically resizes the array if you add to it.  However, when you call a DLL, the DLL cannot tell LabVIEW to increase the size of the array as it builds it.  So, the array needs to be large enough for the DLL to fill it up, or you could cause memory corruption/crashing.
    Depending on how your DLL has been written, you may be able to use the DLL to help you.  A lot of times, you specify the length as an input with the array, and the DLL checks to see if you have enough memory allocated.  If not, then the call generates an error, and the output of the len input is how big an array is needed.  So, you make a call with a size that typically is going to be large enough, and check for the error.  If you get the error, then you resize your LabVIEW array, and call the function again to get all the data.  Another option is to always call it with 0 elements, knowing you will get an error, then allocate the array.
    If the DLL has not been written to verify you have specified enough memory, then you need to allocate an array you believe is big enough.

  • Variable Size Error.

    Hi Experts,
    I am using a variable to get the error message and use that in sending mail, but when i ran the scenario its error out saying,
    "ORA-12899: value too large for column".
    My assumption is when the error message exceed more than 200 characters its error out. So my question is how to increase the size of the variable size?
    Please help..
    Thanks

    Hi G,
    Thanks for your reply,
    Datatype : AlphaNumeric
    Action: Historize (I tried Not Persistance, last value also).
    please let me know if you need anything.

  • Variable size item problem in BOM

    hi all,
    We have semi-finished material with componets as variable size items (item cat. R)
    Now in the variable size tem data, Size 1 = 1,406 MM, Size 2 = 1,220 MM. Numner is 1 ST, formaula place is blank.
    Qty Var-Sz Item is calculated by system is 3.957 M2. On what basis this value is calculated?
    In the component material we have maintained a componenet scrap quantity as 15%.
    BOM ratio of header : component = 1NOS : 1 ST
    Again when we create a production order for the header, for 1 NOS header quantity component qty becomes 2.
    For 2 NOS of header qty, component becomes 3 like this.
    Why this happens..
    Regards,
    Srijit.

    Thread closed

  • How I can transfer data from the database into a variable (or array)?

    I made my application according to the example (http://corlan.org/2009/06/12/working-in-flash-builder-4-with-flex-and-php/). Everything works fine. I changed one function to query the database - add the two parameters and get the value of the table in String format. A test operation shows that all is ok. If I want to display this value in the text area, I simply drag and drop service to this element in the design mode
    (<s:TextArea x="153" y="435" id="nameText" text="{getDataMeanResult.lastResult[0].name}"  width="296" height="89"  />).
    It also works fine, just a warning and encouraged to use ArrayCollection.getItemAt().
    Now I want to send the value to a variable or array, but in both cases I get an error: TypeError: Error #1010: A term is undefined and has no properties..
    How can I pass a value from the database into a variable? Thank you.
    public var nameTemp:String;
    getDataMeanResult.token = authors.getDataMean(arrayOfNumber[0], dir_id);
    nameTemp = getDataMeanResult.lastResult[0].name;
    public var nameArray:Array = new Array();
    for (var i:uint=o; i<3; i++){
    getDataMeanResult.token = authors.getDataMean(arrayOfNumber[i], dir_id);
    nameArray[i] = getDataMeanResult.lastResult[0].name;
    And how i can use syntax highlighting in this forum?

    Astraport2012 wrote:
    I have to go back to the discussion. The above example works fine when i want to get a single value of the database. But i need to pass an array and get an array, because i want to get at once all the values for all pictures tooltips. I rewrote the proposed Matt PHP-script and it works. However, i can not display the resulting array.
    yep, it won't work for Arrays, you'll have to do something slightly more intelligent for them.
    easiest way would be to get your PHP to generate XML, then read that into something like an ArrayList on your HTTPService result event (depends what you're doing with it).
    for example, you could have the PHP generate XML such as:
    <pictures>
         <location>test1.png</location>
         <location>test2.png</location>
         <location>test3.png</location>
         <location>test4.png</location>
         <location>test5.png</location>
         <location>test6.png</location>
    </pictures>
    then you'll read that in as the ResultEvent, and perform something like this on it
    private var tempAC:ArrayList = new ArrayList
    protected function getStuff_resultHandler(event:ResultEvent):void
        for each(var item:Object in event.result.pictures)
           var temp:String = (item.@location).toString();
           tempAC.addItem(temp);
    in my example on cookies
    http://www.mattlefevre.com/viewExample.php?tut=flash4PHP&proj=Using%20Cookies
    you'll see an example of how to format an XML structure containing multiple values:
    if($_COOKIE["firstName"])
            print "<stored>true</stored>";
            print "<userInfo>
                    <firstName>".$_COOKIE["firstName"]."</firstName>
                    <lastName>".$_COOKIE["lastName"]."</lastName>
                    <userAge>".$_COOKIE["userAge"]."</userAge>
                    <gender>".$_COOKIE["gender"]."</gender>
                   </userInfo>";
        else
            print "<stored>false</stored>";
    which i handle like so
    if(event.result.stored == true)
                        entryPanel.title = "Welcome back " + event.result.userInfo.firstName + " " + event.result.userInfo.lastName;
                        firstName.text = event.result.userInfo.firstName;
                        lastName.text = event.result.userInfo.lastName;
                        userAge.value = event.result.userInfo.userAge;
                        userGender.selectedIndex = event.result.userInfo.gender;
    depends on what type of Array you're after
    from the sounds of it (with the mention of picture tooltips) you're trying to create a gallery with an image, and a tooltip.
    so i'd probably adopt something like
    <picture>
         <location>example1.png</location>
         <tooltip>tooltip for picture #1</tooltip>
    </picture>
    <picture>
         <location>example2.png</location>
         <tooltip>tooltip for picture #2</tooltip>
    </picture>
    <picture>
         <location>example3.png</location>
         <tooltip>tooltip for picture #3</tooltip>
    </picture>
    etc...
    or
    <picture location="example1.png" tooltip="tooltip for picture #1"/>
    <picture location="example2.png" tooltip="tooltip for picture #2"/>
    <picture location="example3.png" tooltip="tooltip for picture #3"/>
    etc...

  • How to crate a dynamic size array, collection

    Hi,
    Can someone point me to some tutorial on how to create a dynamic size array. Actually I have multiple cursors and on different tables and want to loop through each cursor and get some values from each cursor and put it in an array. But don't know how to create or initialize an array as I don't know the size. Is there any other way.
    Here is what I am doing I have 6 cursors on different tables, I loop through each cursor and get some specific data that I need to place at one place after looping through all the cursors which then finally needs to be inserted in one table. But before the insert I need to validate each data so want to have all the data in some array or some other place for temporary storage from it's easier to do the validate and insert rather than while looping through the cursors as there may be duplicates which I am trying to remove.
    As this procedure will be called multiple times so wanted to save the cursor data in temporary array before inserting in the final table. Looking for some faster and efficient way.
    Any help is appreciated.
    Thanks

    guest0012 wrote:
    All the 6 cursors are independent and no relation i.e. can have a join and have one sql as no relationship in tables.If there is no relation, then what are your code doing combining unrelated rows into the same GTT/array?
    Now using GTT when I do an insert how do I make sure the same data doesnot already exists. i.e. GTT will only have one column. Then create a unique index or primary key for the GTT and use that to enforce uniqueness.
    So everytime I iterate over a cursor I have to insert into GTT and then finally again have to iterate over GTT and then do an insert in the final table which maybe a performance issue Which is why using SQL will be faster and more scalable - and if PL/SQL code/logic can be used to glue these "no relationship" tables together, why can't that not be done in SQL?
    that's why i was wondering if can use any kind of array or collection as it will be a collection of numbersAnd that will reside in expensive PGA memory. Which means a limit on the size of the collection/array you can safely create without impacting server performance, or even cause a server crash by exhausting all virtual memory and causing swap space to trash.
    and finally will just iterate ovr array and use FOR ALL for insert but don't know what will be the size of the array as I only know after looping the cursors the total number of records to be stored. So wondering if how to do it through collection/array is there a way to intialize the array and keep populating it with the data with defining the size before hand.You cannot append the bulk collect of one cursor into the collection used for bulk collecting another cursor.
    Collections are automatically sized to the number of rows fetched. If you want to manually size collection, the Extend() method needs to be used, where the method's argument specifies the number of cells/locations to add to the collection.
    From what you describe about the issue you have - collections are not the correct choice. If you are going to put the different tables's data into the same collection, then you can also combine those tables's data using a single SQL projection (via a UNION for example).
    And doing the data crunching side in SQL is always superior in scalability and performance, than doing it in PL/SQL.

  • Variable size item:

    Hi
    Company procures copper sheet of certain thickness with different sizes. Stock keeping dimension is KG. Material master has alternative unit of measure and conversion factor for KG and cubic centimeter. Design department will enter this sheet dimension like 15005003 in BOM and it will correctly calculate KG with formula entered.
    My problem is shop floor person will come to know the dimension and KG relation but how store person will come to know what size he has to cut and issue against production order. As while issuing goods he can only see quantity in KG and not in cubic centimeters ?
    Surendra

    SDBSAP ,
    If its unanswered why you flaged it answered .......?
    and solution to your problem in standard sap is not possible.
    You need to go for development, logic can be , for all variable size items from a BOM you need to pick size 1 size 2 and size 3 to print on issue slip . It will give exact dimension to your storage person to issue the correct dimension sheet to shop floor.
    Regards
    Ritesh

  • Variable size items.

    Hi, im a PP consultant from bombay, i had a query regarding a client who is inti\o wooden frame manufacturing it is a strictly discrete industry and the client specifications vary with almost every request. at the moment the client is creating a new mat master for every new product thus causing the master materials to run into 50-60 thousand currently. i want to know if i can use variable size items to reduce the number of materials defined as all of the materials are from standard sized planks. stock is required to be maintained for all components individually.

    Hi,
    "If you want different-sized sections of a material (raw material) to be represented by one material number in BOM items, you use this item category."
    Ans lies in the your last statement(stock is required to be maintained for all components individually)You cannot go for variable size item as you need to maintain stock individually
    Revert if you have further query
    Reward points if useful
    Regards,
    SVP

Maybe you are looking for